Count(*) vs Count(1) vs Count(column)

because 1 is an expression, there is no difference between Count(*) and Count(1). But Count(column) is completely different from Count(*). The reason is Count(column) ignore NULL but Count(*) means Count all rows NULL or NOT NULL.

Tip: All aggregate functions ignore NULL except COUNT(*)

This entry was posted in Joy of T-SQL, T-SQL Tips & Tricks. Bookmark the permalink.

One Response to Count(*) vs Count(1) vs Count(column)

  1. chebum says:

    Didn’t know it, thanks.

Leave a comment

Fill in your details below or click an icon to log in: Logo

You are commenting using your account. Log Out / Change )

Twitter picture

You are commenting using your Twitter account. Log Out / Change )

Facebook photo

You are commenting using your Facebook account. Log Out / Change )

Google+ photo

You are commenting using your Google+ account. Log Out / Change )

Connecting to %s