SQL/Joins 9 min
Joins
Combine rows from two tables that share a key.
inner joinleft joinkeys
Normalised databases split data across tables. A JOIN stitches them back together by matching a key — usually a foreign key pointing at another table's primary key.
sql · editable
loading editor…
Try it: Keep only the completed orders.
An INNER JOIN (the default) keeps only rows that match on both sides. A LEFT JOIN keeps every row of the left table and fills the right-hand columns with NULL where nothing matched — that is how you find customers with no orders.
sql · editable
loading editor…
Joins and aggregation combine naturally: join first to widen the rows, then GROUP BY to summarise them.