When we execute select count(*) from table_name
it returns the number of rows.
What does count(1)
do? What does 1
signify here
SELECT COUNT(1) from
should do the exact same thing as
SELECT COUNT(*) from
There may have been or still be some reasons why it would perform better than SELECT COUNT(*)
on some database, but I would consider that a bug in the DB.
SELECT COUNT(col_name) from
however has a different meaning, as it counts only the rows with a non-null value for the given column.
- 热议问题