In the previous article regarding sql left outer join we learnt left outer join that retrieves all the results from left table and related matches from the right table where right table having no matches displays the Null value in the corresponding columns. Consider the same example of authors and publishers table of the existing database PUBS of sql server 2000.
We used the following left outer join query:
SELECT A.AU_FNAME, A.AU_LNAME, P.PUB_NAME FROM AUTHORS A LEFT OUTER JOIN PUBLISHERS P ON A.CITY = P.CITY ORDER BY A.AU_LNAME, A.AU_FNAME
Just change the left keyword to right outer join in above example; you will get the reverse output of left outer join in the form of right outer join.
SQL Right Outer Join query Example:
SELECT A.AU_FNAME, A.AU_LNAME, P.PUB_NAME FROM AUTHORS A RIGHT OUTER JOIN PUBLISHERS P ON A.CITY = P.CITY ORDER BY A.AU_LNAME, A.AU_FNAME
Result:
au_fname
au_lname
pub_name
NULL
New Moon Books
Binnet & Hardley
Five Lakes Publishing
Ramona Publishers
GGG&G
Scootney Books
Lucerne Publishing
Abraham
Bennet
Algodata Infosystems
Cheryl
Carson
Notice the difference in the output of right outer join and left outer join. Right outer join returned all the rows from right table as all publisher names and null values for the left table columns having no match found in left table’s au_fname and au_lname.
Learn SQL Joins from Examples of SQL Inner Join also...
Be the first to rate this post
Tags: sql, sql joins, sql outer joins, sql right outer join, sql left outer join, sql join examples
10/11/2008 3:20:16 AM