Thursday, 20 October 2011

SQL FULL JOIN



The FULL JOIN keyword return rows when there is a match in one of the tables.


Syntax 

SELECT column_name(s)
FROM table_name1
FULL JOIN table_name2
ON table_name1.column_name=table_name2.column_name



Pur


OrderNo
custname
city
1
Siva
Srivilliputtur
2
Bala
Sivakasi
3
Kanna
Madurai


PurDet


sno
OrderNo
qty
rate
1
2
50
70
2
2
30
56
3
1
100
200
4
3
30
30
5
1
60
80




Example :


SELECT Pur.OrderNo as PurOrdNo,Pur.custname, Pur.City,PurDet.Orderno as PurDetOrdNo
FROM Pur
Full Join PurDet
ON Pur.Orderno=PurDet.OrderNo 
ORDER BY Pur.CustName

Output :


PurOrdNo
custname
city
PurDetOrdNo
NULL
NULL
NULL
5
NULL
NULL
NULL
4
2
Bala
Sivakasi
2
2
Bala
Sivakasi
2
3
Kannan
Madurai
NULL
1
Siva
Srivilliputtur
1




Quick Links :

      Refer Left  & Right Join ....  Click Me 
 

No comments:

Post a Comment


”Back