Beginner

403. RIGHT JOIN

Learn how RIGHT JOIN keeps all records from the right table and matching records from the left table.

📘 Lesson 403 of 728 ⏱ 11 min 🎯 Intermediate

RIGHT JOIN returns all rows from the right table and matching rows from the left table. If no match exists, columns from the left table contain NULL.

RIGHT JOIN can be useful when the right-side table must remain complete while related information is optional.

Return all departments, including departments that currently have no employees.

SQL
SELECT
    e.EmployeeName,
    d.DepartmentName
FROM Employees e
RIGHT JOIN Departments d
    ON e.DepartmentID = d.DepartmentID;

RIGHT JOIN can be used in organizational reporting, reference-data analysis, and completeness checks.

  • RIGHT JOIN keeps all rows from the right table.
  • Matching left-side rows are included.
  • Unmatched left-side values become NULL.
  • RIGHT JOIN is also called RIGHT OUTER JOIN.
  • A RIGHT JOIN can often be rewritten as a LEFT JOIN by changing table order.
What does RIGHT JOIN return?

It returns all rows from the right table and matching rows from the left table.

Can RIGHT JOIN be rewritten as LEFT JOIN?

Yes. The table order can usually be reversed to achieve the same result using LEFT JOIN.

Have you finished this lesson?

Introduction to SQL – All Lessons