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 JOIN semantics.
  • Compare RIGHT JOIN vs LEFT JOIN query readability.
  • Re-order tables to prefer LEFT JOIN for 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 JOIN by 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

Challenge 1: Convert RIGHT JOIN

Rewrite SELECT * FROM orders o RIGHT JOIN customers c ON o.customer_id = c.customer_id using a LEFT JOIN.


Summary

RIGHT JOIN preserves all rows from the right table. Reordering tables to use LEFT JOIN is preferred for readability.