The short answer
GROUP BY combines rows into groups so aggregate functions can operate on each group.
SELECT department, COUNT(*)
FROM employees
GROUP BY department;Output might be:
IT 20
HR 10
Finance 15If you select a normal column that isn't in GROUP BY and isn't aggregated:
SELECT department, name, COUNT(*)
FROM employees
GROUP BY department;SQL doesn't know which employee name to return for each department.
So most SQL dialects reject it.