3

Query 1:

SELECT COUNT(1) FROM STUDENTS

Query 2:

SELECT COUNT(*) FROM STUDENTS

Both the queries return the same result, but is there any performance difference between these two ?

What I had heard is the first query would be faster than the second one, but can any one give specific details about it?

mtk
  • 13,221
  • 16
  • 72
  • 112
  • possible duplicate of [Count(*) vs Count(1)](http://stackoverflow.com/questions/1221559/count-vs-count1) –  Aug 27 '12 at 06:40

2 Answers2

4

You may use count(*) or count(1), one is not faster than the other. As stated, is just a urban legend :)


One final note, count(*) and count(columnName) may be different!
The first one counts all rows, the second one counts the number of rows where the specified column is not NULL.

Jonathan Leffler
  • 730,956
  • 141
  • 904
  • 1,278
aF.
  • 64,980
  • 43
  • 135
  • 198
1

There is no difference whatsoever between the two statements.

The rumour that count(1) is faster is an urban legend that was never true.