2

I was wondering what is difference between Count(*) and Count(1) for the query optimization. On researching on it I came across Ask Tom which is for oracle and states that both are identical in terms of time taken for execution.

  1. Is is also applicable to SQL Server 2008?
  2. And if yes then why are there are two diff function for the same?
  3. If no which to use for better optimization?
  4. Are there any cases where should we use Count(*) over Count(1) and vice-a-verse
DoctorAV
  • 1,189
  • 1
  • 14
  • 40

2 Answers2

2

COUNT (*) is the same as COUNT(1). The reality is that the “*” is actually the default option and it needs not to be specified.The Count(*) includes all the non-NULL values.If you use the column name or any constant in the COUNT function. it will give you NON-NULL values

joshua
  • 2,371
  • 2
  • 29
  • 58
-1

It should be same. As per definition of COUNT "COUNT ( { [ [ ALL | DISTINCT ] expression ] | * } )" So 1 is treated as non null expression.