Find the WHERE with Aggregate Mistake
Find the Mistake Medium
Question
This query has an error. Find and fix it:
Code
SELECT user_id FROM orders WHERE COUNT(*) > 5;
Hint
Can you use aggregate functions in WHERE?
Explanation
You cannot use aggregate functions in WHERE — WHERE filters rows before grouping. Use HAVING instead: SELECT user_id FROM orders GROUP BY user_id HAVING COUNT(*) > 5;.
Related Resources
Related Lessons
- GROUP BY
Learn WHERE vs HAVING.
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.