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

后端 未结 9 1858

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:32

    1) count(any integer value) is faster than count(*) ---> gives all counts including null values

    2) count(column_name) omits null

    Ex-->

    column name=> id

    values => 1 1 null null 2 2

    ==> count(0), count(1), count(*) -----> result is 6 only

    ==> count(id) ----> result is 4

提交回复
热议问题