Back to Developer Roadmap

Count Star Vs Count Column

src/data/question-groups/sql-queries/content/count-star-vs-count-column.md

4.0654 B
Original Source

The difference is that COUNT(*) counts all the rows of data, including NULL values, while COUNT(column_name) counts only non-NULL values in the specified column. Let's illustrate this using a table named Users.

userIdfirstNamelastNameagecountry
1JohnDoe30Portugal
2JaneDon31Belgium
3ZachRidge30Norway
4nullTom25Denmark

If you use COUNT(*), the result will be 4 but if you use COUNT(firstName), it will return 3, omitting the null value.