1

I have 2 sql's (each sql is about 10 lines joining about 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?

1
  • Please post up the SQL statements. Commented Sep 7, 2011 at 8:54

1 Answer 1

1
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) )
Sign up to request clarification or add additional context in comments.

1 Comment

well, I end up using coalesce. Thanks for your idea

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.