views:

145

answers:

1

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?

+4  A: 

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.

RodeoClown