Predict GROUP BY Count
Predict Output Medium
Question
Given an `orders` table with user_id values (1, 1, 2, 3, 3, 3), how many rows does this return?
Code
SELECT user_id, COUNT(*) FROM orders GROUP BY user_id;
Hint
Count the distinct user_id values.
Explanation
GROUP BY user_id creates one group per distinct user_id. There are 3 distinct values (1, 2, 3), so 3 rows are returned.
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.