0

I want to know, for removing duplicate rows, which query is better ? (faster and more optimized):

select distinct col from table;

OR

select col from table group by col;

As you see, there is not any aggregate function, So which one is better ? Or in other word, what is the difference between them ?

stack
  • 10,280
  • 19
  • 65
  • 117
  • How would you use DISTINCT to remove duplicate rows? How are you finding duplicates if not with an aggregate function like COUNT()? – Uueerdo Aug 24 '15 at 18:45
  • Possible duplicate of [Is there any difference between GROUP BY and DISTINCT](http://stackoverflow.com/questions/164319/is-there-any-difference-between-group-by-and-distinct) – Erik Dec 21 '15 at 16:38

2 Answers2

0

GROUP BY lets you use aggregate functions, like AVG, MAX, MIN, SUM, and COUNT. Other hand DISTINCT just removes duplicates.

You can read this answer too : https://stackoverflow.com/a/164544/4227703

Community
  • 1
  • 1
seb2020
  • 115
  • 3
  • 10
0

Please use DISTINCT for removing duplicate rows, as this construct was specifically designed for this purpose. It's shorter, easier to read and understand.

Alex Shesterov
  • 26,085
  • 12
  • 82
  • 103