beginner
RIGHT JOIN
5 min readLast updated: 2026-07-23
Overview
A RIGHT JOIN (or RIGHT OUTER JOIN) returns all records from the right table, along with matching records from the left table.
Learning Objectives
- Understand
RIGHT JOINsemantics. - Compare
RIGHT JOINvsLEFT JOINquery readability. - Re-order tables to prefer
LEFT JOINfor consistency.
Detailed Concept Explanation
RIGHT JOIN is the exact inverse of LEFT JOIN. It preserves all rows from the right table regardless of whether a matching record exists in the left table.
In practice, most SQL developers avoid RIGHT JOIN and simply swap the order of tables inside a LEFT JOIN to make queries easier to read from left to right.
Code Examples
SQL
sql
-- RIGHT JOIN example
SELECT
e.name AS employee_name,
d.dept_name
FROM employees e
RIGHT JOIN departments d ON e.department_id = d.department_id;
-- Equivalent LEFT JOIN (Preferred for readability)
SELECT
e.name AS employee_name,
d.dept_name
FROM departments d
LEFT JOIN employees e ON d.department_id = e.department_id;
Best Practices
- Prefer LEFT JOIN: Standardize code bases on
LEFT JOINby placing driving tables first. This improves query scannability.
Interview Perspective
Note
Interview Question: Can any RIGHT JOIN be converted into a LEFT JOIN?
Yes. Simply swap the order of the two tables in the FROM and JOIN clauses. A RIGHT JOIN B is logically identical to B LEFT JOIN A.
Interactive Challenges
Summary
RIGHT JOIN preserves all rows from the right table. Reordering tables to use LEFT JOIN is preferred for readability.