Multiple Oracle Query
I have 2 sql's (each sql is about 10 lines joining ab开发者_开发问答out 5 tables). These 2 sqls returns same column. I want to execute sql2 only if sql1 returns no result.
How to do this in one sql?
query1
UNION ALL
( query2
WHERE NOT EXIST (query1)
)
In Oracle you can also factor:
WITH conditional_query AS (query1)
SELECT * FROM conditional_query
UNION ALL
( query2 WHERE NOT EXIST (SELECT NULL FROM conditional_query) )
精彩评论