The main difference between COUNT(*) and COUNT(column) lies in what they count and how they handle NULL values.
COUNT(*) counts all rows in a table, including those that contain NULL values in any column. It doesn’t care about what’s inside the row — every row is counted.
Example:
SELECT COUNT(*) FROM Employees;
This will return the total number of rows in the Employees table, even if some columns (like Salary or DepartmentID) have NULLs.
On the other hand, COUNT(column) counts only the rows where that specific column has a non-NULL value.
Example:
SELECT COUNT(Salary) FROM Employees;
This will count only those employees who have a Salary value — any row where Salary is NULL will be excluded.
To make it clearer:
| EmployeeID | Name | Salary |
|---|---|---|
| 1 | John | 50000 |
| 2 | Mary | NULL |
| 3 | David | 60000 |
COUNT(*)→ 3 (counts all rows)COUNT(Salary)→ 2 (ignores Mary’s row because Salary is NULL)
I’ve used both in different scenarios — for example, during data completeness checks. In one ETL validation project, I used COUNT(*) to check if all expected rows were loaded from the source, and COUNT(column) to ensure that important fields like CustomerID or TransactionDate weren’t missing values.
One challenge I’ve faced is when people assume COUNT(*) is slower than COUNT(column). In reality, most modern SQL engines optimize both similarly — the performance difference is negligible unless the column is indexed.
So in short —
- Use
COUNT(*)when you want total rows, including NULLs. - Use
COUNT(column)when you want non-NULL values for a specific column.
