03, 11 chapters
joins and subqueries
everything.joins
joins and subqueries
putting tables back together. every join, semi and anti joins, subqueries, set operations and CTEs.
- 03.01joins, in one picturea join is a filtered cross product. why the venn diagram lies to you.
- 03.02INNER JOINmatching rows across tables, ON vs USING vs NATURAL, and joining three tables in a row.
- 03.03LEFT, RIGHT and FULL joinskeep the rows that didn't match, padded with NULLs. and the WHERE that turns them back into inner joins.
- 03.04self joins and CROSS JOINa table joined to itself to find each employee's manager, and every pair of rows on purpose.
- 03.05join fan-outtwo one-to-many joins and your totals triple. aggregate first, then join.
- 03.06subqueriesa query wherever a value or a table can go. scalar, table and correlated subqueries.
- 03.07EXISTS, semi joins and anti joinsis there a match? the join that never duplicates, the one that keeps only the lonely rows, and relational division.
- 03.08the NOT IN trapone NULL in the list and NOT IN returns nothing at all. NOT EXISTS doesn't care.
- 03.09LATERAL joinsa subquery that can see the row to its left. the latest three orders per customer, in one join.
- 03.10UNION, INTERSECT and EXCEPTstacking results instead of joining them. and why UNION ALL is usually what you meant.
- 03.11WITH and CTEsnaming a subquery so you can read your own query. inlined by default, MATERIALIZED when you ask.