3

Possible Duplicate:
What is the difference between select count(*) and select count(any_non_null_column)?

I have a column with the type of char(0). some of the rows are NULL and some of them are empty(''). The question is that when I run the following query, the result will be 0. SELECT count(id) FROM test WHERE id IS NULL

but when I run the following query, the result is correct: SELECT count(*) FROM test WHERE id IS NULL

I have one column,why is that the case?

Alireza
  • 3,636
  • 10
  • 37
  • 44

1 Answers1

6
  • COUNT(somecolumn) ignores NULLs
  • COUNT(*) won't

You can see this with

SELECT count(id),count(*) FROM test WHERE id IS NULL

Coincidently, all aggregate functions ignore NULL except COUNT(*)

gbn
  • 69,809
  • 8
  • 163
  • 243