• Articles
  • Tutorials
  • Interview Questions

SQL RIGHT JOIN Explained with Examples

Tutorial Playlist

The Right Join returns all values of the right table and the matched rows from the left table.

What is RIGHT JOIN in SQL?

RIGHT JOIN is a keyword, which is used to select all rows from the right table and also the matched values between the two tables.

RIGHT JOIN in SQL

The RIGHT JOIN basically returns all records from the right table and the matched records from the left table. For example, let’s say, we have two tables, Table A and Table B, when the left join is applied to these two tables, it would give all records from Table B and only the matched records from Table A.
A Brief Introduction to Right Join

Go for this in-depth job-oriented SQL Training Course now!

SQL RIGHT JOIN Syntax

SELECT columns
FROM table1 name
RIGHT JOIN table2 name
ON table1.coumn_x = table2.column_y;

where SELECT, RIGHT JOIN, and ON are the keywords, columns is the list of columns, table1 is the first table and table2 is the second table, and column_x and column_y are the columns for performing the RIGHT JOIN, followed by a semicolon.

Become a Database Architect

SQL RIGHT JOIN Example

Let’s apply SQL RIGHT JOIN to two tables, the employee table, and the department table:

Select employee.e_name, employee.e_dept, department.d_name, department.d_location from employee
RIGHT JOIN department
ON employee.e_dept = department.d_name;

Stay up-to-date on the latest SQL Join features!

Syntax

 

After writing the query, click on the execute button to check for errors. Once the query is executed, a message appears like “Commands completed successfully”.
This brings us to the end of this tutorial section. Go ahead and link the tables from your database to get a better insight into your data. In the next tutorial section, we will discuss the Full Join.

Wish to crack SQL interviews? Intellipaat’s Top SQL Interview Questions are meant only for you!

Course Schedule

Name Date Details
SQL Training 20 Apr 2024(Sat-Sun) Weekend Batch
View Details
SQL Training 27 Apr 2024(Sat-Sun) Weekend Batch
View Details
SQL Training 04 May 2024(Sat-Sun) Weekend Batch
View Details

Database-ad.jpg