Sunday, May 3, 2015

SQL Right Outer Join

The right outer join returns a result table with the matched data of two tables then remaining rows of the right table and null for the left table's columns.
Right Outer Join Syntax is,
select column-name-list
from table-name1 
RIGHT OUTER JOIN 
table-name2
on table-name1.column-name = table-name2.column-name;
Right outer Join Syntax for Oracle is,
select column-name-list
from table-name1, 
table-name2
on table-name1.column-name(+) = table-name2.column-name;

Example of Right Outer Join

The class table,
IDNAME
1abhi
2adam
3alex
4anu
5ashish
The class_info table,
IDAddress
1DELHI
2MUMBAI
3CHENNAI
7NOIDA
8PANIPAT
Right Outer Join query will be,
SELECT * FROM class RIGHT OUTER JOIN class_info on (class.id=class_info.id);
The result table will look like,
IDNAMEIDAddress
1abhi1DELHI
2adam2MUMBAI
3alex3CHENNAI
nullnull7NOIDA
nullnull8PANIPAT

No comments:

Post a Comment