SQL JOINs Explained Visually (INNER, LEFT, RIGHT, FULL)
A JOIN matches each row of one table to rows in another using a join key. The join type decides what happens to rows that find no match. Watching it row by row makes the difference obvious.
▶ Open the INNER JOIN example in SQL Visualizer
What a JOIN does
Our movies table stores a director_id, and the directors table stores the matching name. A JOIN lines them up on that shared key:
SELECT m.title, m.genre, d.name AS director
FROM movies m
INNER JOIN directors d ON m.director_id = d.director_id
ORDER BY m.revenue DESC
LIMIT 20INNER JOIN — keep only matches
An INNER JOIN returns a row only when both sides match. A movie with a director_id that has no matching director simply disappears from the result.
LEFT JOIN — keep every left row
A LEFT JOIN keeps every row from the left (first) table. When the right side has no match, its columns come back as NULL instead of dropping the row. Use it when the left table is the one you must not lose rows from.
SELECT m.title, d.name AS director
FROM movies m
LEFT JOIN directors d ON m.director_id = d.director_idRIGHT and FULL OUTER JOIN
- RIGHT JOIN keeps every row from the right table (mirror of LEFT).
- FULL OUTER JOIN keeps unmatched rows from both sides, filling the gaps with
NULL.
When the JOIN runs
JOINs happen early — right after FROM and before WHERE. So the rest of the query operates on the already-combined rows. See the full sequence in SQL execution order.
Common pitfalls
- Forgetting the
ONcondition produces a cross join — every row paired with every row. - Filtering the right table of a
LEFT JOINinWHEREquietly turns it back into an inner join; put that condition in theONclause instead. - Join keys with different types (text vs integer) may match nothing — cast them.