COUNT Function
Question
What does COUNT(*) return?
Hint
COUNT(*) includes NULL rows; COUNT(col) excludes NULLs.
Explanation
COUNT(*) returns the total number of rows in a group, including rows with NULL values. COUNT(column) counts non-NULL values in the column. COUNT(DISTINCT column) counts unique non-NULL values. Example: if a table has 100 rows and 20 have NULL email, COUNT(*) = 100, COUNT(email) = 80, COUNT(DISTINCT email) might be less. COUNT(*) is the most common aggregate. For large tables, COUNT(*) can be slow without indexes.
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.