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

Thread: Compatible query for outer join..

  1. #1
    Join Date
    Sep 2001
    Location
    Düsseldorf, Germany.
    Posts
    588
    SELECT e.ename, a.street_address, a.city,a.state,a.post_code
    FROM emp e, addr a
    WHERE e.empno = a.empno(+)
    AND a.state = 'TEXAS'

    Which is the compatible ANSI/ISO query for the above mentioned query (A or B)

    A)

    SELECT e.ename, a.street_address, a.city,a.state,a.post_code
    FROM emp e RIGHT OUTER JOIN addr a
    ON (e.empno = a.empno)
    AND a.state = 'TEXAS'

    B)

    SELECT e.ename, a.street_address, a.city,a.state,a.post_code
    FROM emp e LEFT OUTER JOIN addr a
    ON (e.empno = a.empno)
    AND a.state = 'TEXAS'


    Thanks

    Sameer

  2. #2
    Join Date
    Apr 2002
    Posts
    14
    Sameer

    b - LEFT OUTER JOIN is the correct form of those two.

    However SQL-92 provides a simpler syntax assuming the two columns have only the empno column in common -

    SELECT e.ename, a.street_address, a.city,a.state,a.post_code
    FROM emp e NATURAL LEFT OUTER JOIN addr a

    Alternatively if other columns share names you could use: -

    SELECT e.ename, a.street_address, a.city,a.state,a.post_code
    FROM emp e LEFT OUTER JOIN addr a USING(empno)

    Andy

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