Skip to content
Related Articles

Related Articles

Improve Article
SQL Right Join
  • Last Updated : 26 Apr, 2021

The RIGHT JOIN keyword in SQL returns the all matching records(or rows) and the records(or rows) which are present in the right table but not in the left table .That means that, if a certain row is present in the right table but not in the left, the result will include this row but with a NULL value in each column from the left . If a record from the left table is not in the right, it will not be included in the result.


The syntax for a RIGHT JOIN is :-

SELECT column_name(s) 
FROM tableA 
RIGHT JOIN tableB ON tableA.column_name = tableB.column_name;


In this example we will consider two tables employee table containing details of the employees working in the particular department the and department table containing the details of the department

employee table :

E1Varun SinghalD1
E2Amrita AggarwalD2
E3Ravi AnandD3

department table :


To perform right- join on these two tables we will use the following SQL query:

select emp_no , emp_name ,d_name, location 
from employee 
right join dept on employee.dept_no = department.dept_no;

The output that we will get is as follows : 

E1Varun SinghalITDelhi
E2Amrita AggarwalHRHyderabad
E3Ravi AnandFinancePune

As right join gives the matching rows and the rows that are present in the left table but not in the right table .Here  in this example ,we see that the department that contains no employee contains [NULL] values of emp_no and emp_name after performing the right join.

Attention reader! Don’t stop learning now. Get hold of all the important CS Theory concepts for SDE interviews with the CS Theory Course at a student-friendly price and become industry ready.


My Personal Notes arrow_drop_up
Recommended Articles
Page :