What is the difference between count(0), count(1).. and count(*) in mySQL/SQL?

后端 未结 9 1863

I was recently asked this question in an interview. I tried this in mySQL, and got the same results(final results). All gave the number of rows in that particular table. Can

9条回答
  •  失恋的感觉
    2020-12-24 02:26

    COUNT(*) will count the number of rows, while COUNT(expression) will count non-null values in expression and COUNT(column) will count all non-null values in column.

    Since both 0 and 1 are non-null values, COUNT(0)=COUNT(1) and they both will be equivalent to the number of rows COUNT(*). It's a different concept, but the result will be the same.

提交回复
热议问题