Back to SQL Notes
Topic #96

RIGHT JOIN in SQL

RIGHT JOIN (or RIGHT OUTER JOIN) returns every row from the right table, plus matching data from the left table — the mirror image of LEFT JOIN.

employees departments

🔵 Shaded = all of departments (right table) is kept, matched or not.

Reference Tables Used in This Section

Every join note below uses these same two tables, so you can see exactly how each join type treats the same data differently.

employees

idnamedepartment_id
1Aman1
2Riya2
3Karan1
4NehaNULL

departments

iddepartment_name
1Engineering
2Marketing
3Sales

Notice: Neha has no department (department_id is NULL), and Sales has no employees at all. These two "unmatched" rows are what make the differences between join types visible.

Syntax

SELECT columns
FROM table1
RIGHT JOIN table2 ON table1.column = table2.column;

Example

SELECT e.name, d.department_name
FROM employees e
RIGHT JOIN departments d ON e.department_id = d.id;

Expected Output:

namedepartment_name
AmanEngineering
KaranEngineering
RiyaMarketing
NULLSales

All 3 departments appear — including Sales, which has no employees, shown with NULL in name. Neha (no department) is excluded, since she's on the unkept left side.

Dialect Note

MySQL, PostgreSQL, and SQL Server all support RIGHT JOIN. Oracle historically didn't support the keyword the same way in older versions (used (+) operator syntax instead) — modern Oracle supports standard RIGHT JOIN too.

Practical Use Case

Same logic as LEFT JOIN, just from the other side — useful when it reads more naturally to lead with the table you want all rows from. In practice, most SQL style guides prefer rewriting a RIGHT JOIN as a LEFT JOIN with the tables swapped in FROM, since it's more consistently supported and easier to scan when reading top-to-bottom.

Common Mistakes

  • Using RIGHT JOIN out of habit from how the tables happen to be listed, instead of just swapping table order and using LEFT JOIN — functionally identical, but LEFT JOIN is far more common in real codebases, so it's easier for teammates to read
  • Assuming RIGHT JOIN behaves differently from a swapped LEFT JOIN — it doesn't; they're mirror images

Interview Relevance

Q: "Can every RIGHT JOIN be rewritten as a LEFT JOIN?" Yes — swap the table order in FROM/JOIN and change the keyword; the result is identical. Interviewers ask this to see if you understand joins conceptually rather than as memorized keyword patterns.

Practice Question

Rewrite the RIGHT JOIN example above as an equivalent LEFT JOIN query.

Want to go beyond the notes?

Join Coding Now Tech Institute's SQL course — live mentorship, real projects, and 100% placement support.

Enroll Now — Free Demo Available

RIGHT JOIN in SQL – FAQs

Quick answers about learning RIGHT JOIN in SQL in SQL.

This free note from Coding Now Tech Institute explains RIGHT JOIN in SQL in SQL — concept, syntax and worked code examples you can copy, run and revise before interviews.
Yes. Every SQL topic on Coding Now Tech Institute, including RIGHT JOIN in SQL, is 100% free with no signup required.
With focused practice, most students grasp RIGHT JOIN in SQL in 1–3 days from these notes; pairing it with Coding Now Tech Institute's mentor-led course takes you to job-ready depth faster.
Use the code examples in this note, then ask doubts for free on the Coding Now Tech Institute Community (/community) — expert instructors answer within 24 hours.
Call NowEnroll Now