I have a table
num
----
NULL
NULL
NULL
NULL
55
NULL
NULL
NULL
99
when I wrote
select COUNT(*)
from tbl
where num is null
the output was 7
but when I wrote
select COUNT(num)
from tbl
where num is null
the output was 0
what’s the difference between these two queries ??
Difference is in the field you select.
When counting
COUNT(*)NULL values are taken into account (count all rows returned).When counting
COUNT(num)NULL values are NOT taken into account (count all non-null fields).That is a standard behavior in SQL, whatever the DBMS used
Source. look at COUNT(DISTINCT expr,[expr…])