Skip to main content

Aggregating for SQLs

Aggregating in SQL means collapsing many rows into summary values using functions such as COUNT, SUM, AVG, MIN and MAX together with GROUP BY. HAVING filters the resulting groups, and set operators like UNION and INTERSECT combine the output of separate queries. It turns raw records into totals, averages and counts for reports.

Stage: Query Basics · Part of the SQL roadmap · Last reviewed 19 November 2026

What to learn in Aggregating

Aggregating interview questions

What is the difference between COUNT(*) and COUNT(column)?

COUNT(*) counts all rows in the group, including those with NULLs. COUNT(column) counts only rows where that column is not NULL. COUNT(DISTINCT column) counts unique non-NULL values. Choosing the wrong one is a common cause of off-by-some totals.

What is the difference between UNION and UNION ALL?

UNION combines results and removes duplicate rows, which requires a sort or hash step. UNION ALL keeps every row, including duplicates, and is faster. Use UNION ALL unless you actually need deduplication, and make sure both queries return the same number of compatible columns.

Where Aggregating fits in the SQL roadmap

Aggregating belongs to the Query Basics stage (beginner level), which takes about 18 hours. Ask the database questions.

Back to the full SQL roadmap