count(*) vs count(row-name) - which is more correct?
Posted
by bread
on Stack Overflow
See other posts from Stack Overflow
or by bread
Published on 2010-06-09T06:14:16Z
Indexed on
2010/06/09
6:22 UTC
Read the original article
Hit count: 198
sql
Does it make a difference if you do count(*)
vs count(row-name)
as in these two examples?
I have a tendency to always write count(*)
because it seems to fit better in my mind with the notion of it being an aggregate function, if that makes sense.
But I'm not sure if it's technically best as I tend to see example code written without the *
more often than not.
count(*):
select customerid, count(*), sum(price)
from items_ordered
group by customerid
having count(*) > 1;
vs. count(row-name):
SELECT customerid, count(customerid), sum(price)
FROM items_ordered
GROUP BY customerid
HAVING count(customerid) > 1;
© Stack Overflow or respective owner