What's better, GROUP BY or DISTINCT
Posted on 2006-04-08
If I want to get distinct values, I can use either DISTINCT or GROUP BY - the usage can vary of course, but this two queries:
SELECT DISTINCT city FROM clients
SELECT city FROM clients GROUP BY city
the resultset will be identical. I have heard or read somewhere that using DISTINCT should be avoided if possible - I don't insist on this statement but since it's sitting somewhere at the back of my head, I'm just wondering, is it really bad to use DISTINCT in this case (the size of the table can be rather big), or using GROUP BY is better. And if yes, what's the advantage of one over another and vice versa.