Home >Database >Mysql Tutorial >COUNT(*) vs. COUNT(column-name): When Should I Use Each?
When to Use COUNT(*) vs. COUNT(column-name)
In SQL, both COUNT(*) and COUNT(column-name) are commonly used aggregate functions to count the number of rows in a dataset. However, there are subtle differences between them.
COUNT(*)
COUNT(*) counts all rows in a table or specified set, regardless of whether individual columns have NULL values. Essentially, it counts the entire row, including any empty cells.
COUNT(column-name)
COUNT(column-name) counts only the non-NULL values in a specific column. If a row has a NULL value in the specified column, it will not be included in the count.
Specific Use Cases
Additional Points
The above is the detailed content of COUNT(*) vs. COUNT(column-name): When Should I Use Each?. For more information, please follow other related articles on the PHP Chinese website!