Saturday, May 12, 2012

SQL FULL JOIN

Hello Friends, welcome to this post where I will discuss about the SQL FULL JOIN. and this is the last one for JOINs in SQL.

So by now we are aware of the SQL INNER JOIN, LEFT JOIN, RIGHT JOIN. Now lets check the FULL JOIN.

Lets look at our Tables,

Table1: Customer

CID     Name         Designation
222     Whiskey       Moderator
444     Onty            Member
111     Gaurav         Admin
333     Kumaar       Admin
555     Rishabh       Admin
666     Rose           Admin
888     White          Member
999     Mikey         Member

Table2: Orders

OID     Product         CID
1           Perfume        666
2           Laptop          444
3           Perfume        999
4           Cell Phone    666


SQL FULL JOIN will return all the records from the left and right tables and the matched case will have all the info.

SYNTAX:

SELECT column_name
FROM table1
FULL JOIN table2
ON table1.column_name=table2.column_name


So for our query:

SELECT Customer.Name, Orders.Product
FROM Customer
FULL JOIN Orders
ON Customer.CID=Orders.CID


Our result-set will have:

Name                Orders
Whiskey      
Onty                  Laptop
Gaurav        
Kumaar      
Rishabh      
Rose                 Perfume
Rose                 Cell Phone
White        
Mikey               Perfume

So I guess nothing more to explain this, as this is very simple, but if you have doubts do not hesitate to drop in a comment.

Thats all for this post, Do Not Forget to check my next post.

Thank You!

0 comments:

Post a Comment