COUNT(*) vs COUNT(1) vs COUNT(column_name)

COUNT(*)

  • It counts all the rows including NULLs.
  • When * is used as an argument, it simply counts the total number of rows including the NULLs.


COUNT(1)

  • It counts all the rows including NULLs.
  • With COUNT(1), there is a misconception that it counts records from the first column. What COUNT(1) really does is that it replaces all the records you get from query result with the value 1 and then counts the rows meaning it even replaces a NULL with 1 meaning it takes NULLs into consideration while counting.


COUNT(column_name)

  • It counts all the rows but not NULLs.
  • When a column name is used as an argument, it simply counts the total number of rows excluding the NULLs meaning it will not take NULLs into consideration.