简体   繁体   中英

What is difference between distinct and group by (without aggregate function)

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 ?

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

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

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM