RAJ
Free

SQL Joins, Explained Visually

The same two tables, four joins — see the SQL, the rows, and where the NULLs come from.

SELECT c.id, c.name, o.id, o.amount
FROM customers c
INNER JOIN orders o ON o.customer_id = c.id;

Only rows that match on BOTH sides. Dana (no orders) and order 103 (no customer) both vanish.

customersorders

Result (3 rows)

c.idc.nameo.ido.amount
1Ava10040
1Ava10125
2Ben10260

customers

idname
1Ava
2Ben
3Cara
4Dana

orders

idcustomer_idamount
100140
101125
102260
103510

Runs entirely in your browser.

The one idea that makes joins click

A join is about which unmatched rows survive. INNER keeps only rows that match on both sides. LEFT keeps every left row and pads the missing right side with NULL. RIGHT does the mirror. FULL keeps everything from both. The data is identical — only the treatment of the rows that don't match changes.

Why NULLs appear (and the interview trap)

The NULLs in an outer join are the whole point — they mark rows with no match. The classic mistake is filtering on a right-table column in the WHERE clause of a LEFT JOIN, which silently turns it back into an INNER JOIN by dropping those NULL rows. Put such conditions in the ON clause instead.

A note on RIGHT and FULL

LEFT JOIN is far more common than RIGHT in real code — any RIGHT JOIN can be rewritten as a LEFT by swapping the tables, which most people find easier to read. Some databases (older SQLite included) don't support RIGHT/FULL at all, so knowing the LEFT equivalent is genuinely useful.

SQL is the core analyst skill

Data, business and product analyst roles, scraped daily from company career pages.

Browse analyst jobs
Raj