SQL RIGHT JOIN


The RIGHT JOIN returns all the values from the rows of right table. It also includes the matched values from left table but if there is no matching in both tables, it returns NULL.

Syntax

SELECT table1.column1, table2.column2...
FROM table1
RIGHT JOIN table2
ON table1.common_field = table2.common_field;

Example

customer Table

idnamesalary
1Ashwani6000
2Sachin5000
3Soun1000
4Deepak2000
5Ravi2000

order Table

dateo_idcust_idamount
20-02-201500123000
12-04-201500222000
22-06-201500334000
11-08-201500445000
SELECT id, name, amount,date
FROM customer
RIGHT JOIN order
ON customer.id = order.cust_id;
Output
idnameamountdate
2Sachin300020-02-2015
2Sachin200012-04-2015
3Soun400022-06-2015
4Deepak500011-08-2015

Share this article on