What does “select count(1) from table_name” on any database tables mean?

前端 未结 9 586
被撕碎了的回忆
被撕碎了的回忆 2020-12-22 18:38

When we execute select count(*) from table_name it returns the number of rows.

What does count(1) do? What does 1 signify here

9条回答
  •  情话喂你
    2020-12-22 19:32

    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.

    提交回复
    热议问题