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

Thread: Sql - Join

  1. #1
    Join Date
    Feb 2003
    Location
    Slovakia, Europe
    Posts
    72

    Sql - Join

    Hi,

    I have a problem...

    I know that oracle use (+) instead JOIN...

    SELECT * FROM tabA, tabB, tabC
    WHERE tabA.b_id = tabB.id (+)
    AND ???? -- I need join tabB with tabC but null values (from A in column b_id) have to be in result...


    SQL>
    SELECT * FROM tabA,tabB,tabC
    WHERE tabA.b_id = tabB.id (+)
    AND tabB.c_id = tabC.id;
    this command doesnt work correct...


  2. #2
    Join Date
    Nov 2002
    Location
    Geneva Switzerland
    Posts
    3,142

    Re: Sql - Join

    If I understand correctly that you want all the rows from tabA:

    SELECT * FROM tabA,tabB,tabC
    WHERE tabA.b_id = tabB.id(+)
    AND tabB.c_id = tabC.id(+);

    You need the second (+) because there will be rows from tabC "missing" as well.

  3. #3
    Join Date
    Feb 2003
    Location
    Slovakia, Europe
    Posts
    72

    hmm

    doesn't work...

    i thought about it like you, but doesn't work

  4. #4
    Join Date
    Nov 2002
    Location
    Geneva Switzerland
    Posts
    3,142
    Well - it works for me:
    Code:
      1  select p.swpersonid, m.swpersonid, a.rlaccountid
      2  from  sw_person p, rl_m2m_account_rel m, rl_account a
      3  where p.swpersonid = 123456789
      4  and   p.swpersonid = m.swpersonid(+)
      5* and   m.rlaccountid = a.rlaccountid(+)
    
    SWPERSONID SWPERSONID RLACCOUNTID
    ---------- ---------- -----------
     123456789
    What happens for you?

  5. #5
    Join Date
    Nov 2002
    Location
    Geneva Switzerland
    Posts
    3,142
    Just a thought - if you put addional conditions on columns in tabB or tabC, then you need to allow for NULL values:

    SELECT * FROM tabA,tabB,tabC
    WHERE tabA.b_id = tabB.id(+)
    AND tabB.c_id = tabC.id(+)
    AND (tabB.otherCol = 'Valid' OR tabB.otherCol IS NULL);

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