SQL RIGHT JOIN returns all the values from the right table and it also includes the records matching from left table. The result will be NULL if no matching in left table.

The syntax for the RIGHT JOIN is

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

                                                                 Or

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

 

Example:

Let us consider two tables

1.Employee table

IdEmployee_NameEmpl_AgeMonthly package
1Sushil2218000
2Bhargav3245000
3Mohanthy2625000
4Nithin3852000

 

 

2.Payment Table

Payment_IDDateEmployee_IdAmount
15023-02-201612500
15130-06-201525000
15214-09-201646500

 

 

Now we RIGHT JOIN these tables

SELECT ID, Employee_Name, Amount, Date
FROM Employee
RIGHT JOIN Payment
ON Employee.ID=Payment.Employee_Id;

 

The result will be displayed as follows

Employee_IDEmployee_NameAmountDate
1Sushil250023-02-2016
2Bhargav500030-06-2015
4Nithin650014-09-2016