Find the GROUP BY Mistake
Find the Mistake Medium
Question
This query has an error. Find and fix it:
Code
SELECT user_id, name, COUNT(*) FROM orders GROUP BY user_id;
Hint
Every non-aggregated column in SELECT must be in GROUP BY.
Explanation
The name column is in the SELECT but not in the GROUP BY. When using GROUP BY, every non-aggregated column must appear in the GROUP BY clause. Fix: either add name to GROUP BY, or remove name from SELECT.
Related Resources
Related Lessons
- GROUP BY
Learn GROUP BY rules.
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.