Reading Room · Module 03
Track 0/9 (0%)
Course completion
Module 03 · Joins~24 min · 8 worked queries

Relational Joins & Preservation Semantics

Pair tuples across relations using INNER, LEFT, RIGHT, FULL, SELF, CROSS, and anti-join idioms while tracking preserved vs unmatched rows.

Trace Live in StudioAll Modules
Core Relational Rule
JOIN constructs a combined tuple space before WHERE runs; moving a right-table filter from ON to WHERE silently turns a LEFT JOIN into an INNER JOIN.Module 03 · Joins · Reading Room

Mental Model

  1. 01.

    Think of a join as matching candidates from two sets across a predicate gate: matching pairs fuse into wide rows.

  2. 02.

    LEFT / RIGHT / FULL OUTER joins rescue unmatched rows by padding the missing side with NULLs after ON evaluation.

  3. 03.

    Anti-joins use LEFT JOIN followed by WHERE right.key IS NULL to surface orphans — users without orders.

  4. 04.

    Self-joins attach two aliases to the same table so peer rows (same department, paired teammates) can meet.

Frequent Pitfall to Avoid
Filtering nullable right-hand columns in WHERE instead of ON after a LEFT JOIN, which discards every NULL-padded orphan row.

Interactive Module Lab · Joins

13. LEFT JOIN (Users & Orders) — sql
SELECT users.name, orders.product_name, orders.amount, orders.status
FROM users
LEFT JOIN orders ON users.id = orders.user_id
ORDER BY orders.amount DESC;
Execution Stages4 steps
Stage 01 · FROM

SOURCE: USERS

10 in → 10 out

Scanned 10 rows from table 'users'.

#idnamedepartment_idrolesalarystate
11Alice Smith1Software Engineer95,000keep
22Bob Jones2Product Manager110,000keep
33Charlie Lee1Software Engineer88,000keep
44Diana Prince3UX Designer76,000keep
55Evan Wright2Data Analyst82,000keep
66Fiona Gallagher1Tech Lead135,000keep
77George ClarkNULLIntern42,000keep
88Hannah Abbott2Scrum Master89,000keep
Inspect each evaluated clause in 13. LEFT JOIN (Users & Orders) or animate every row moving between stages in Studio.Open 13. LEFT JOIN (Users & Orders) in Studio →

Worked Presets in This Module

12. INNER JOIN (Users & Departments)

Each user is paired with the department row whose id matches. Rows without a partner are dropped.

13. LEFT JOIN (Users & Orders)

Every user is kept. Users with no orders get NULLs on the order side instead of disappearing.

14. RIGHT JOIN keeps the other side

Marketing has no employees, but a RIGHT JOIN keeps every department and fills the user side with NULL.

15. FULL JOIN keeps both sides

Unmatched rows from either table survive: George (no department) and Marketing (no staff).

16. Anti-join: who has no orders?

LEFT JOIN, then keep only the rows where the right side is NULL. A classic way to find "missing" things.

17. Chaining three tables

Joins run left to right. The result of the first join becomes the input of the second.

18. Self join: pairs of teammates

A table can join itself by using two aliases. "a.id < b.id" stops each pair showing up twice.

19. CROSS JOIN: every combination

No condition at all: every department is paired with every product category (4 x 2 = 8 rows).

Navigation

LivePreparation

Client-side workspace · saved locally