View Full Version : Quick COUNT() question

07-21-2006, 11:35 AM
The MySQL documentation says:

COUNT(DISTINCT expr,[expr...])

Returns a count of the number of different non-NULL values.

How do i get it to INCLUDE null values? I am using COUNT with the DISTINCT bit as well, and i want the NULL rows to count as one as well.


07-21-2006, 12:49 PM
what are you trying to count? Distinct tools for instance?

If you have
wrench, wrench, hammer, null, null, null, screwdriver

and you are trying to count the distinct things then you have 3 tools.
if you are trying to count the nulls in there as well each null is distinct from the other so you have six tools. Is that really what you want?

In order to count nulls you need count(*) but of course that would include two counts for wrench.

07-21-2006, 01:59 PM
Actually ive realised i was trying to do the wrong thing and it works differently now. Thanks anyway.