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

后端 未结 9 1868

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

    The result will be the same, however COUNT(*) is slower on a lot of production environments today, because in production the db engines can live decades. I prefer to use COUNT(0), someone use COUNT(1), but definitely not COUNT(*) even if its lets say safe to use on modern db engines, I would not depend on the engine, especially if its only one character difference, also the code will be more portable.

提交回复
热议问题