SQL Full Join

SQL FULL JOIN is used to combine all the rows of two tables.

It is the combination of both left and right joins and it returns NULL if no matchings are found in either left or right table.

 

The syntax for FULL JOIN is

SELECT column_name(s)
FROM table1
FULL JOIN table2
ON table1.column_name=table2.column_name;

                                                          Or

SELECT column_name(s)
FROM table1
FULL  OUTER JOIN table2
ON table1.column_name=table2.column_name;


Example

Let us consider an example

1.Employee table

Id Employee_Name Empl_Age Monthly package
1 Sushil 22 18000
2 Bhargav 32 45000
3 Mohanthy 26 25000
4 Nithin 38 52000

 

2.Payment Table

Id Employee_Name Empl_Age Monthly package
1 Sushil 22 18000
2 Bhargav 32 45000
3 Mohanthy 26 25000
4 Nithin 38 52000

 

Now applying FULL JOIN on the tables

SELECT ID, Employee_Name, Amount, Payment_ID
FROM Employee
FULL JOIN Payment
ON Employee.ID=Payment.Employee_ID;

 

The result table will be as follows:

Employee_ID Employee_Name Amount Payment_ID
1 Sushil 2500 150
2 Bhargav 5000 151
3 Mohanthy NULL NULL
4 Nithin 6500 152