GUIDEDeep dive
SQL JOIN and GROUP BY
JOIN combines two tables on a key, GROUP BY groups rows by a dimension, and aggregates compute per group. After a JOIN, decide what one row means before choosing the GROUP BY grain.
JOIN
INNER JOIN keeps rows matched on both sides.
LEFT JOIN keeps all left rows and fills missing right values with NULL.
GROUP BY
Non-aggregated SELECT columns belong in GROUP BY.
HAVING filters groups after aggregation; WHERE filters rows before.
FAQ
COUNT(*) vs COUNT(col)?
COUNT(*) counts rows; COUNT(col) ignores NULL.
Can I GROUP BY multiple columns?
Yes; the grain is the combination of those columns.
Sources
Related calculators
SQL Queries: 1000 Gamified SELECT Practice Cards1000 SQL query cards covering SELECT, WHERE, JOIN, GROUP BY, HAVING and subqueries, in 50 levels with spaced repetition.More guides
Hiragana vs KatakanaRead guideSpaced Repetition and the Forgetting CurveRead guideOn Readings vs Kun ReadingsRead guideAn N5 Kanji Study OrderRead guideKEEP READING
Keep reading
Read in order, or jump to another guide on the same topic.
← PreviousSQL SELECT Basics: WHERE, ORDER, LIMITThe minimal query structure for filtering, sorting and limiting rows.Next →How to Read Python OutputExpressions, repr, operator precedence and common traps.