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

后端 未结 9 1862

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

    Now - they should all perform identically.

    In days gone by, though, COUNT(1) (or whatever constant you chose) was sometimes recommended over COUNT(*) because poor query optimisation code would make the database retrieve all of the field data prior to running the count. COUNT(1) was therefore faster, but it shouldn't matter now.

提交回复
热议问题