Compare Options: INNER, LEFT, RIGHT and FULL JOIN
A JOIN combines rows from two tables. The type of JOIN decides what happens to rows that have no partner in the other table. Using the same two tiny tables for every type is the easiest way to see the difference.
The two practice tables
students
| id | name |
|---|---|
| 1 | Aiko |
| 2 | Bruno |
| 3 | Cara |
clubs (which student joined which club)
| student_id | club |
|---|---|
| 1 | Chess |
| 2 | Drama |
| 4 | Robotics |
Notice two things: Cara (id 3) has no club, and the Robotics row points to a student id 4 that does not exist.
INNER JOIN: only matching pairs
SELECT students.name, clubs.club
FROM students
INNER JOIN clubs ON clubs.student_id = students.id;
| name | club |
|---|---|
| Aiko | Chess |
| Bruno | Drama |
Cara and Robotics both disappear, because neither has a partner.
LEFT JOIN: everything from the left table
SELECT students.name, clubs.club
FROM students
LEFT JOIN clubs ON clubs.student_id = students.id;
| name | club |
|---|---|
| Aiko | Chess |
| Bruno | Drama |
| Cara | NULL |
Every student appears. Cara gets NULL for the club, meaning "no match".
RIGHT JOIN: everything from the right table
It is the mirror image: every club row appears, and Robotics gets NULL for the name. RIGHT JOIN is less common because you can always swap the table order and use LEFT JOIN instead. SQLite added RIGHT and FULL joins only in recent versions, so older SQLite will not accept them.
FULL OUTER JOIN: everything from both
Every student and every club row appears. Matches are paired up; Cara appears with a NULL club, and Robotics appears with a NULL name. MySQL does not support FULL OUTER JOIN directly; people combine a LEFT and a RIGHT join with UNION instead.
The comparison at a glance
| Join type | Unmatched left rows (Cara) | Unmatched right rows (Robotics) | Typical use |
|---|---|---|---|
| INNER | dropped | dropped | "Show students and their clubs" |
| LEFT | kept, with NULLs | dropped | "Show all students, with their club if any" |
| RIGHT | dropped | kept, with NULLs | Same as LEFT with tables swapped |
| FULL | kept | kept | Comparing two lists to find gaps on either side |
How to read your own results
- Count the rows you expected before running the query.
- If rows are missing, you may need a LEFT JOIN instead of an INNER JOIN.
- If NULLs appear where you did not expect them, a row had no partner. That can be correct, or it can reveal messy data like the Robotics row.
A handy trick
To find students with no club, use a LEFT JOIN and keep only the NULLs:
SELECT students.name
FROM students
LEFT JOIN clubs ON clubs.student_id = students.id
WHERE clubs.student_id IS NULL;
This returns Cara. For a gentle step-by-step version of these ideas, see INNER JOIN and LEFT JOIN, one small step at a time.
A free learning page for beginners. Practise on a test database, never on real customer data, and check the official documentation for your database version.