Step 9
5 min read

RIGHT JOIN

Learn RIGHT JOIN - the opposite of LEFT JOIN.

What is RIGHT JOIN?

JOIN Types Comparison
JOIN TypeShows
INNER JOINOnly matches
LEFT JOINAll from left table
RIGHT JOINAll from right table
FULL OUTER JOINAll from both tables
4 rows

RIGHT JOIN shows ALL rows from the right table, even if there is no match in the left table.

Simple analogy: Opposite of LEFT JOIN. Shows all classes and which students are enrolled (even empty classes).

Basic Example

JOIN Types Comparison
JOIN TypeShows
INNER JOINOnly matches
LEFT JOINAll from left table
RIGHT JOINAll from right table
FULL OUTER JOINAll from both tables
4 rows
SELECT students.name, enrollments.course FROM students RIGHT JOIN enrollments ON students.id = enrollments.student_id;

Shows all enrollments, even if student does not exist.

When to Use

JOIN Types Comparison
JOIN TypeShows
INNER JOINOnly matches
LEFT JOINAll from left table
RIGHT JOINAll from right table
FULL OUTER JOINAll from both tables
4 rows

Rarely used! LEFT JOIN is more common.

Most people rewrite RIGHT JOIN as LEFT JOIN by switching table order.

What Comes Next

JOIN Types Comparison
JOIN TypeShows
INNER JOINOnly matches
LEFT JOINAll from left table
RIGHT JOINAll from right table
FULL OUTER JOINAll from both tables
4 rows

Next: FULL OUTER JOIN (shows all records from both tables)

Finished this topic?

Mark it complete to track your progress and maintain your streak!

SkillsetMaster - AI, Web Development & Data Analytics Courses