Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

sybase - Is there any performance difference between count(*) and count(1)

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?

like image 891
mtk Avatar asked Jan 29 '26 15:01

mtk


1 Answers

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.

like image 114
aF. Avatar answered Feb 01 '26 09:02

aF.



Donate For Us

If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!