开发者

Multiple Oracle Query

开发者 https://www.devze.com 2023-04-03 09:18 出处:网络
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.

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) )
0

精彩评论

暂无评论...
验证码 换一张
取 消