GROUP BY Purpose
Question
What does GROUP BY do?
Hint
GROUP BY is used with aggregate functions.
Explanation
GROUP BY groups rows that have the same values in specified columns into summary rows. SELECT department, COUNT(*) FROM employees GROUP BY department counts employees per department. GROUP BY is used with aggregates: COUNT, SUM, AVG, MIN, MAX. Each group produces one row. Columns in SELECT (outside aggregates) must appear in GROUP BY. Use HAVING (not WHERE) to filter groups. GROUP BY can group by multiple columns. The order of groups is not guaranteed without ORDER BY.
Related Resources
Related Lessons
- GROUP BY
Learn GROUP BY.
Look up unfamiliar terms
A beginner-friendly glossary explains jargon in plain English — variables, functions, DOM, Promise, and more.
Decode error messages
Plain-English explanations of common errors — what they mean, why they happen, and how to fix them.
Build real projects
Apply what you learned by building guided projects with starter code and solutions.