DBAsupport.com Forums - Powered by vBulletin
Results 1 to 4 of 4

Thread: does sql manage exclusivity ?

  1. #1
    Join Date
    Sep 2002
    Posts
    2
    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

  2. #2
    Join Date
    Nov 2000
    Location
    Pittsburgh, PA
    Posts
    4,166
    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.

  3. #3
    Join Date
    Sep 2002
    Posts
    2
    This is not exactly what I need.

    I need:
    if t2 is not empty, then t2
    if t2 is empty, then t1

    thanks

  4. #4
    Join Date
    Dec 2000
    Location
    Ljubljana, Slovenia
    Posts
    4,439
    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
  •  


Click Here to Expand Forum to Full Width