[ACCEPTED]-Performance of COUNT SQL function-aggregate

Accepted answer
Score: 24

Performance should not matter because they 2 do 2 different aggregates

  • COUNT(*) is all rows, including NULLs
  • COUNT(some_column_name), excludes NULL in "some_column_name"

See the "Count(*) vs Count(1)" question 1 for more

Score: 4

Option 2 actually counts all the fields 7 where some_column_name is not null. Option 1 counts all 6 the fields where any field is not null. So 5 you might actually get different results 4 out of these two queries. Most of the time 3 you actually want to count all the rows, and 2 then the fastest option, which does not 1 check for any of the fields, is simply SELECT COUNT(1) FROM ...

Score: 1

No, there is no performance gain in Sql 1 Server.

More Related questions