-
With sql we can make unions and intersections.
But does sql manage exclusivity?
Imagine we have 2 tables:
- one containing "all the people"
- the second containing "a short list of people", which can be empty
Can we create a view containing: the "list", if not empty, otherwise the "all people table" ?
In other words I need a different join (inner or outer) depending on the existence of a not empty table.
Thanks for your help,
Nadina
-
select * from t1 where not exists ( select * from t2)
/
you can also do
select * from t1 where c1 not in (
select c1 from t2)
So the answer is yes.
-
This is not exactly what I need.
I need:
if t2 is not empty, then t2
if t2 is empty, then t1
thanks
-
It might not be the most efficient query in the world, but will give you what you want:
SELECT * FROM t2
UNION ALL
SELECT * FROM t1 WHERE NOT EXISTS
(SELECT NULL FROM t2 WHERE ROWNUM=1);
Jurij Modic
ASCII a stupid question, get a stupid ANSI
24 hours in a day .... 24 beer in a case .... coincidence?
Posting Permissions
- You may not post new threads
- You may not post replies
- You may not post attachments
- You may not edit your posts
-
Forum Rules
|
Click Here to Expand Forum to Full Width
|