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

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

    This is similar to the difference between

    SELECT * FROM table_name and SELECT 1 FROM table_name.  
    

    If you do

    SELECT 1 FROM table_name
    

    it will give you the number 1 for each row in the table. So yes count(*) and count(1) will provide the same results as will count(8) or count(column_name)

提交回复
热议问题