SQL VISUALIZER

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 20
For each movie, find the director whose id matches.

INNER 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_id
Every movie appears, even ones with an unknown director.

RIGHT and FULL OUTER JOIN

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

▶ Open the INNER JOIN example in SQL Visualizer