RIGHT JOIN — Complete Guide
RIGHT JOIN — Complete Guide: free step-by-step lesson with examples, common mistakes, and interview tips — part of MySQL Tutorial on Toolliyo Academy.
On this page
MySQL Tutorial · Lesson 23 of 100
RIGHT JOIN
Basics → Advanced
Basics · 1 — SQL · ~6 min · MySQL — Joins & Relationships
What is this?
RIGHT JOIN mirrors LEFT JOIN but keeps all rows from the right table. MySQL supports it; teams usually flip tables and use LEFT JOIN for readability.
Why should you care?
Rare in code reviews — but knowing it helps when reading legacy SQL from vendors or exports.
See it live — copy this example
Run in MySQL Workbench or the mysql CLI.
SELECT o.order_ref, c.full_name
FROM customers c
RIGHT JOIN orders o ON o.customer_id = c.customer_id;
What happened?
- Every order appears even if customer row was deleted (orphan order).
- Missing customers show NULL name — data quality alarm.
Practice next
- Simulate orphan order in dev (skip customer insert).
- Run RIGHT JOIN query.
- Rewrite as orders LEFT JOIN customers — same result.
- Find orphan orders: WHERE c.customer_id IS NULL.
- Convert query to LEFT JOIN form and diff results.
Remember
RIGHT JOIN preserves right table rows. Prefer LEFT JOIN + table order swap in new code. Useful for reading old scripts.
DataFlow audit of orphan orders
Compliance finds orders pointing at deleted customers via RIGHT JOIN report.
Outcome: FK rules tightened before next release.
Interview prep for this lesson
Practice these questions aloud after reading—each links to a full structured answer.
Sign in to ask a question or upvote helpful answers.
No questions yet — be the first to ask!