SQL RIGHT JOIN - The Coding Shala

Home >> Learn SQL >> SQL RIGHT JOIN


The SQL RIGHT JOIN is a part of the OUTER JOIN. The SQL RIGHT JOIN or SQL RIGHT OUTER JOIN returns all the records from the right table and matching records from the left table. If there is no match in the left table then it returns NULL values from the left table.
SQL RIGHT JOIN - The Coding Shala


The basic syntax of the RIGHT JOIN is as follows - 

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


The following two tables are used for the examples - 
Table 1. 'emp' table 

emp_id     emp_name     city     dept_no     salary  
 1          Akshay        Pune      101       50000  
 3          Nikhil        Pune      101       51000  
 5          Mohit         Delhi     103       40000  
 6          Shubham       Surat     105       42000  
 7          Akash         Mumbai    106       45000  

Table 2. 'dept' table 

dept_no     dept_name      total_emp  
 101          Product Dev       50  
 102          Consulting       100  
 103          Product Consult   20  
 104          Marketing        150  
 105          Sales            250  

The following SQL statement is an example of SQL RIGHT JOIN - 

select emp.emp_id, emp.emp_name,  
 dept.dept_no, dept.dept_name  
 from emp  
 right join dept on emp.dept_no = dept.dept_no;

Other Posts You May Like
Please leave a comment below if you like this post or found some error, it will help me to improve my content.


Popular Posts from this Blog

Shell Script to find sum, product and average of given numbers - The Coding Shala

Shell Script to Create a Simple Calculator - The Coding Shala

Add two numbers in Scala - The Coding Shala

New Year Chaos Solution - The Coding Shala

Richest Customer Wealth LeetCode Solution - The Coding Shala