i have a problem for my current query, i wish to get record/result based on a column (example column Status have the value of new/pending/completed for the query i execute if there are 3 record with status new,it should be filter to show 1 record with status new only). Below is my current query which get duplicate column .
select a.CW_UPD_TMS,
case when a.CW_CRT_UID='AAA' then 'BBB'
else a.CW_CRT_UID end as CW_CRT_UID,
COALESCE(b.CW_S_BR, a.CW_S_BR) as CW_S_BR,
a.CW_TRX_STAT as STATUS,
SUBSTR(a.CW_UPD_TMS,7,2) as day,
SUBSTR(a.CW_UPD_TMS,5,2) as month,
SUBSTR(a.CW_UPD_TMS,1,4) as ayear,
SUBSTR(a.CW_UPD_TMS,9,2) as hours,
SUBSTR(a.CW_UPD_TMS,11,2) as mins,
SUBSTR(a.CW_UPD_TMS,13,2) as secs,
case when cast(SUBSTR(a.CW_UPD_TMS,9,2) as INT) > 12 then 'PM'
else 'AM' end as zone
from TABLEA a
left outer join TABLEB b on a.CW_CRT_UID = b.CW_S_USR
where a.CW_TRX_ID = '20150415110000798'
union
select a.CW_UPD_TMS,
case when a.CW_CRT_UID='AAA' then 'BBB'
else a.CW_CRT_UID end as CW_CRT_UID,
COALESCE(b.CW_S_BR, a.CW_S_BR) as CW_S_BR,
a.CW_TRX_STAT as STATUS,
SUBSTR(a.CW_UPD_TMS,7,2) as day,
SUBSTR(a.CW_UPD_TMS,5,2) as month,
SUBSTR(a.CW_UPD_TMS,1,4) as ayear,
SUBSTR(a.CW_UPD_TMS,9,2) as hours,
SUBSTR(a.CW_UPD_TMS,11,2) as mins,
SUBSTR(a.CW_UPD_TMS,13,2) as secs,
case when cast(SUBSTR(a.CW_UPD_TMS,9,2) as INT) > 12 then 'PM'
else 'AM' end as zone
from TABLEC a
left outer join TABLEB b on a.CW_CRT_UID = b.CW_S_USR
where a.CW_TRX_ID = '20150415110000798'
Here is current result:
CW_UPD_TMS CW_CRT_UID CW_S_BR STATUS DAY MONTH AYEAR HOURS MINS SECS ZONE
2015062610260746811 happy KLC NEW 26 06 2015 10 26 07 AM
2015062610273984711 happy KLC NEW 26 06 2015 10 27 39 AM
2015062610275762511 happy KLC NEW 26 06 2015 10 27 57 AM
so now how do i change the query so that only show 1 record only (show with min(CW_UPD_TMS)) as now 3 record have same STATUS (New) .
my expected result should be :
CW_UPD_TMS CW_CRT_UID CW_S_BR STATUS DAY MONTH AYEAR HOURS MINS SECS ZONE
2015062610260746811 happy KLC NEW 26 06 2015 10 26 07 AM
sorry for my poor english.