Most joins match rows by a shared column. These two do something different: one multiplies, the other folds a table against itself.
1 CROSS JOIN
Pairs every row of table A with every row of table B. Three rows times three rows make nine — no ON clause at all.
2 Cartesian product
That every-row-times-every-row output is called a cartesian product. Row counts explode fast, so reach for it on purpose.
3 Self join
A table can join itself: employees holds workers AND managers. Aliases give the two copies different names.
4 Same table, two roles
FROM employees e JOIN employees m ON e.manager_id = m.id reads one table twice, once per alias.
Joins that break the pattern
CROSS JOIN1Pairs every row of table A with every row of table B. Three rows times three rows make nine — no ON clause at all. Cartesian product2That every-row-times-every-row output is called a cartesian product. Row counts explode fast, so reach for it on purpose. Self join3A table can join itself: employees holds workers AND managers. Aliases give the two copies different names. Same table, two roles4FROM employees e JOIN employees m ON e.manager_id = m.id reads one table twice, once per alias. 4 building blocks make up Joins that break the pattern
Press play: the engine reads employees twice — as e (each worker) and m (the manager directory) — and links matching rows.
SELECT e.name AS employee, m.name AS manager
FROM employees e
JOIN employees m
ON e.manager_id = m.id;
employees e
| id | name | dept | salary | manager_id |
|---|
| 1 | Ava | Engineering | 92000 | 1 |
| 2 | Ben | Engineering | 74000 | 1 |
| 3 | Emma | Engineering | 81000 | 1 |
| 4 | Chloe | Sales | 68000 | 1 |
| 5 | Dev | Sales | 55000 | 4 |
| 6 | Finn | Marketing | 62000 | 1 |
employees m
| id | name | dept | salary | manager_id |
|---|
| 1 | Ava | Engineering | 92000 | 1 |
| 2 | Ben | Engineering | 74000 | 1 |
| 3 | Emma | Engineering | 81000 | 1 |
| 4 | Chloe | Sales | 68000 | 1 |
| 5 | Dev | Sales | 55000 | 4 |
| 6 | Finn | Marketing | 62000 | 1 |
| employee | manager |
|---|
| press play — rows will appear here |
Step 1/8FROM lists the same table twice: employees e is the worker side, employees m is the manager side. One table, two aliases.
Same nested-loop plan as any join — the engine just reads the same table twice under two names.
process decision input / output start / end A CROSS JOIN needs no ON clause. How many rows come back, and in what order?
Your predicted output — one line per console line
Hint: CROSS JOIN makes 3 × 2 = 6 rows. ORDER BY sorts alphabetically, so L comes before M, and Blue before Red.
Click a term, then click its description to lock the pair.
5 conceptsTap a card to expand ?CROSS JOINdrops into place
?Self joindrops into place
?Alias (e, m)drops into place
?Cartesian productdrops into place
?ON e.manager_id = m.iddrops into place
01CROSS JOIN multiplies: A rows × B rows, with no ON clause.
02Cartesian products grow fast — cross join small tables on purpose.
03A self join reads one table twice under two aliases.
04e.manager_id = m.id turns flat rows into a reporting chain.
05Aliases are what make one table play two roles.