I need a DB2 V8, SQL Query cursor as below.
(SELECT COL1, COL2
FROM TABLE1 T1 , TABLE2 T2
WHERE T1.COL3=T2.COL4
ORDER BY 1 DESC
, 2 DESC
FETCH FIRST 1 ROW ONLY)
UNION ALL
(SELECT COL1, COL2
FROM TABLE1 T1 , TABLE2 T2
WHERE T1.COL3=T2.COL4
ORDER BY 1 DESC
, 2 DESC
FETCH FIRST 1 ROW ONLY)
ORDER BY 1 DESC
, 2 DESC
FETCH FIRST 1 ROW ONLY ;
FROM TABLE1 T1 , TABLE2 T2
WHERE T1.COL3=T2.COL4
ORDER BY 1 DESC
, 2 DESC
FETCH FIRST 1 ROW ONLY)
UNION ALL
(SELECT COL1, COL2
FROM TABLE1 T1 , TABLE2 T2
WHERE T1.COL3=T2.COL4
ORDER BY 1 DESC
, 2 DESC
FETCH FIRST 1 ROW ONLY)
ORDER BY 1 DESC
, 2 DESC
FETCH FIRST 1 ROW ONLY ;
Will this be possible?
I tried the following SQL to get this done,
SELECT COL1, COL2
from (SELECT COL1, COL2
FROM TABLE1 T1 , TABLE2 T2
WHERE T1.COL3=T2.COL4
ORDER BY 1 DESC
, 2 DESC
FETCH FIRST 1 ROW ONLY) as temp1
UNION ALL
SELECT COL1, COL2
from (SELECT COL1, COL2
FROM TABLE1 T1 , TABLE2 T2
WHERE T1.COL3=T2.COL4
ORDER BY 1 DESC
, 2 DESC
FETCH FIRST 1 ROW ONLY) as temp2
ORDER BY 1 DESC
, 2 DESC
FETCH FIRST 1 ROW ONLY ;
from (SELECT COL1, COL2
FROM TABLE1 T1 , TABLE2 T2
WHERE T1.COL3=T2.COL4
ORDER BY 1 DESC
, 2 DESC
FETCH FIRST 1 ROW ONLY) as temp1
UNION ALL
SELECT COL1, COL2
from (SELECT COL1, COL2
FROM TABLE1 T1 , TABLE2 T2
WHERE T1.COL3=T2.COL4
ORDER BY 1 DESC
, 2 DESC
FETCH FIRST 1 ROW ONLY) as temp2
ORDER BY 1 DESC
, 2 DESC
FETCH FIRST 1 ROW ONLY ;
But I am facing the error as :
"DSNT408I SQLCODE = -199, ERROR: ILLEGAL USE OF KEYWORD FETCH. TOKEN ) UNION
EXCEPT WAS EXPECTED "
I am unable to solve the issue and get the required functionality.
Plz help me ..!!!!!!