GUIDE深度 · Deep 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.

更新 2026-10-30 · 公式可核验

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 guide