views:

70

answers:

2

Am trying to do the union of the results of two queries. But I'm getting the following error: Error at Command Line:9 Column:81 Error report: SQL Error: ORA-00907: missing right parenthesis 00907. 00000 - "missing right parenthesis"

SELECT application_id, clicks, datee, client_id FROM(
(select 
    APPL_CD AS application_id, 
    count(*) as clicks, 
    to_date((to_char(ACTN_TAKE_DATA_TM, 'dd-mm-yyyy')), 'dd-mm-yyyy') as datee, 
    ALRT_RSPNS_FROM_CLIENT_ID AS client_id 
from  ALRT_PLATFORM_ALRT_HSTRY
    where  ACTN_TAKE_CD is not null 
    group by to_char(ACTN_TAKE_DATA_TM, 'dd-mm-yyyy'), APPL_CD, ALRT_RSPNS_FROM_CLIENT_ID order by datee) 
UNION ALL
(select 
    APPL_CD AS application_id, 
    count(*) as clicks, 
    to_date((to_char(ACTN_TAKE_DATA_TM, 'dd-mm-yyyy')), 'dd-mm-yyyy') as datee, 
    ALRT_RSPNS_FROM_CLIENT_ID AS client_id 
from  ALRT_PLATFORM_ALRT
    where  ACTN_TAKE_CD is not null 
    group by to_char(ACTN_TAKE_DATA_TM, 'dd-mm-yyyy'), APPL_CD, ALRT_RSPNS_FROM_CLIENT_ID order by datee )
)
+4  A: 

Remove the ORDER BY from the nested queries:

SELECT application_id, clicks, datee, client_id FROM(
(select 
    APPL_CD AS application_id, 
    count(*) as clicks, 
    to_date((to_char(ACTN_TAKE_DATA_TM, 'dd-mm-yyyy')), 'dd-mm-yyyy') as datee, 
    ALRT_RSPNS_FROM_CLIENT_ID AS client_id 
from  ALRT_PLATFORM_ALRT_HSTRY
    where  ACTN_TAKE_CD is not null 
    group by to_char(ACTN_TAKE_DATA_TM, 'dd-mm-yyyy'), APPL_CD, ALRT_RSPNS_FROM_CLIENT_ID) 
UNION ALL
(select 
    APPL_CD AS application_id, 
    count(*) as clicks, 
    to_date((to_char(ACTN_TAKE_DATA_TM, 'dd-mm-yyyy')), 'dd-mm-yyyy') as datee, 
    ALRT_RSPNS_FROM_CLIENT_ID AS client_id 
from  ALRT_PLATFORM_ALRT
    where  ACTN_TAKE_CD is not null 
    group by to_char(ACTN_TAKE_DATA_TM, 'dd-mm-yyyy'), APPL_CD, ALRT_RSPNS_FROM_CLIENT_ID )
)
Quassnoi
Awesome !! Really really Awesome!! Wish I could do more clicks on up vote. But why ORDER BY is the culprit??
HanuAthena
@cedar715: because `Oracle` does not support `ORDER BY` in the nested queries. The resulting order is not guaranteed anyway.
Quassnoi
@Quassnoi, awesome dude! Its really amazing!! +100 (if it is possible) from my side.
Kangkan
A: 

i think you miss right parenthesis at the very end of query

Andrey