MSDN documentation states:
COUNT(*) returns the number of items in a group. This includes NULL values and duplicates.
How can you have a null value in a group? Can anyone explain the point they're trying to make?
The notation COUNT(*) includes NULL values in the total. The notation COUNT( column_name ) only considers rows where the column contains a non- NULL value.
How to Count SQL NULL values in a column? The COUNT() function is used to obtain the total number of the rows in the result set. When we use this function with the star sign it count all rows from the table regardless of NULL values.
1)Count doesnot take NULL values, but Count(*) returns NULL values.
If you have this table
Table1:
Field1 Field2 Field3 --------------------------- 1 1 1 NULL NULL NULL 2 2 NULL 1 3 1
Then
SELECT COUNT(*), COUNT(Field1), COUNT(Field2), COUNT(DISTINCT Field3) FROM Table1
Output Is:
COUNT(*) = 4; -- count all rows, even null/duplicates -- count only rows without null values on that field COUNT(Field1) = COUNT(Field2) = 3 COUNT(Field3) = 2 COUNT(DISTINCT Field3) = 1 -- Ignore duplicates
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With