I’m trying to create a UNION ALL statement in SQL using the FETCH FIRST 1 ROW however when I do that it gives me an error MISSING KEYWORD
Here’s what my SQL looks like:
x
Select * From tabl1 where Date = '04-MAR-2020' FETCH FIRST 1 ROW
UNION ALL
Select * From tabl1 where Date = '05-MAR-2020' FETCH FIRST 1 ROW
is something like this doable. I would like to keep this as a single statement rather than adding a SUBQUERY or anything of that nature.
Advertisement
Answer
Just put each part in parentheses. Works in 12.2, anyway:
( Select * From tabl1 where Date = '04-MAR-2020' FETCH FIRST 1 ROW )
UNION ALL
( Select * From tabl1 where Date = '05-MAR-2020' FETCH FIRST 1 ROW )
My actual test query, for anyone interested was this:
(select object_name
from user_objects
where object_type = 'TABLE'
order by object_name
fetch first 1 row only)
UNION ALL
(select object_name
from user_objects
where object_type = 'VIEW'
order by object_name
fetch first 1 row only);