COUNT(*) vs COUNT(column) vs COUNT(DISTINCT)
The classic question on how each COUNT form treats NULLs and duplicates.
The Question You Will Be Asked
If you sit a SQL interview, expect this within the first ten minutes: What is the difference between COUNT(*), COUNT(column) and COUNT(DISTINCT column)?
It looks trivial, but interviewers use it to check whether you truly understand how aggregates treat NULL values and duplicates. A confident, precise answer signals you have written real queries, not just memorized syntax.
In this lesson we will build a rock-solid mental model so you can answer instantly and explain the why.
COUNT(*) Counts Rows
COUNT(*) counts rows. It does not look at any column values at all, so NULLs are irrelevant. If the table has 100 rows, COUNT(*) returns 100, period.
The asterisk is not multiplying or expanding columns here. It is a special token meaning "count every qualifying row." This is the form you reach for when the question is simply "how many records?"
SELECT COUNT(*) AS total_rows
FROM employees;All lessons in this course
- COUNT(*) vs COUNT(column) vs COUNT(DISTINCT)
- SUM and AVG with NULLs
- MIN, MAX and Non-Numeric Aggregation
- Aggregates Without GROUP BY