This article will introduce in detail the difference between count (*) and count (column) in mysql. For more information, see
This article will introduce in detail the difference between count (*) and count (column) in mysql. For more information, see
Count (*) calculates the number of rows, including NULL
Count (column) calculates the number of rows that a specific column value has, excluding NULL values.
Count () also has a usage method. the usage of count (1) is the same as that of count.
About their performance
1. select count (*) FROM tablename is the optimal choice under any circumstances;
2. minimize select count (*) FROM tablename where col = 'value' queries;
3. prevent the appearance of select count (COL) FROM tablename WHERE COL2 = 'value.
If the table does not have a primary key, count (1) is faster than count.
If a primary key exists, count (primary key, joint primary key) is faster than count.
If the table has only one field, count (*) is the fastest.