Reputation: 13808
I am trying to get a count of each value in a table using the following SQL:
SELECT col, COUNT(col)
FROM table
GROUP BY col
(There's a WHERE clause in the real code, but it has no impact).
When I run this I get results like so:
a - 5
b - 4
<null> - 0
It doesn't matter how many null entries I have, it always shows a count of 0.
Any ideas why?
Upvotes: 17
Views: 9000
Reputation: 13808
Figured it out. Changed the code to use COUNT(*) instead of COUNT(col).
COUNT(col) was not counting any null rows, all other aggregation methods also eliminate nulls from the result set.
Upvotes: 39