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

前端 未结 9 602
被撕碎了的回忆
被撕碎了的回忆 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:12

    Here is a link that will help answer your questions. In short:

    count(*) is the correct way to write it and count(1) is OPTIMIZED TO BE count(*) internally -- since

    a) count the rows where 1 is not null is less efficient than
    b) count the rows

提交回复
热议问题