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

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

    There is no difference.

    COUNT(1) is basically just counting a constant value 1 column for each row. As other users here have said, it's the same as COUNT(0) or COUNT(42). Any non-NULL value will suffice.

    http://asktom.oracle.com/pls/asktom/f?p=100:11:2603224624843292::::P11_QUESTION_ID:1156151916789

    The Oracle optimizer did apparently use to have bugs in it, which caused the count to be affected by which column you picked and whether it was in an index, so the COUNT(1) convention came into being.

提交回复
热议问题