Skip to main content
SQL Bug Hunt Medium +20 XP

GROUP BY Error

This query fails. What's wrong?

SQLFind the bug
1SELECT department, name, COUNT(*)
2FROM employees
3GROUP BY department;
The bug is on line 1

Select the correct fix

Show answer and explanation

Answer: Remove name or add it to GROUP BY

Every non-aggregate column in SELECT must appear in GROUP BY. 'name' is not aggregated or grouped.

Hint: All non-aggregate columns must be in GROUP BY.

What this challenge tests

Bug Hunt in SQL: group-by, aggregation.

Related challenges