java - count(*)和count(1)区别?
PHPz
PHPz 2017-04-18 09:40:38
0
2
511

count(*)和count(1)区别?

PHPz
PHPz

学习是最好的投资!

reply all(2)
阿神

You can see how your sql will be translated by mysql using the following sql

EXPLAIN EXTENDED
SELECT count(*) FROM `table`;
SHOW WARNINGS;

My version is mysql 5.6.26, the following is the translated result:

/* select#1 */ select count(0) AS `count(*)` from `test`.`table`

So, in my opinion, newer versions of mysql no longer have this difference, but I still use count(1) as a habit.

黄舟

When the data records are not empty, there will be no difference in the query results. But when the column queried by COUNT(1) is empty, the empty ones will be removed and not recorded in the statistics. The results of this query It’s different.

Latest Downloads
More>
Web Effects
Website Source Code
Website Materials
Front End Template