COUNT DISTINCT
Predict Output Medium
Question
What does this SQL produce?
Code
-- orders: customer_ids 1, 1, 2, 2, 3, 3
SELECT COUNT(DISTINCT customer_id) FROM orders;
Hint
COUNT DISTINCT counts unique customer_ids.
Explanation
There are 6 rows but only 3 unique customer_ids (1, 2, 3). COUNT(DISTINCT customer_id) returns 3.
Related Resources
Related Lessons
- Aggregations
Learn aggregations.
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.