r/SQL • u/geminigamer369 • Jul 30 '26
Discussion Differences between counts
What is the difference between
COUNT(*)
COUNT(1)
COUNT(column_name)
8
Upvotes
r/SQL • u/geminigamer369 • Jul 30 '26
What is the difference between
COUNT(*)
COUNT(1)
COUNT(column_name)
View all comments
Show parent comment
1
u/markwdb3 When in doubt, test it out. Jul 30 '26 edited Jul 30 '26
To expand on the meaning of
SELECT *vs.COUNT(*)a bit, you can even dig into open source implementations' source code to see how they work. You can see for yourself that the meanings are distinct. In other words the*inSELECT *means "expand to all columns", but inCOUNT(*)it does NOT.Here's what the situation looks like in PostgreSQL:
SELECT * expansion to all columns
COUNT(*) does NOT expand all columns, it is considered a parameterless aggregate
You can find something similar in MySQL which I'll skip unless anyone's interested.
These behaviors are consistent with the aforementioned standard SQL spec. Distinct meanings of
*altogether.