Link to home
Start Free TrialLog in
Avatar of chaos_hooi
chaos_hooi

asked on

SELECT DISTINCT or GROUP BY? Which one is better?

SELECT DISTINCT or GROUP BY all columns? Which one gives a better performance? Or are they the same?

Thanks...
Avatar of jpkemp
jpkemp

Do you mean, is there a performance difference between:

SELECT DISTINCT a, b, c FROM mytable;

and

SELECT a, b, c FROM mytable GROUP BY a, b, c;

I think the CBO would generate the same plan for both of these. I don't know why you would use GROUP BY in this way - it is used to get aggregates.

Jeff
I think GROUP BY is preferable operator than the modifier DISTINCT and in many cases works faster, of course all depends on the query you have ...
I couldn't answer better to your question than this article:
http://technet.oracle.com/products/rdb/pdf/distinct_derivedtables_groupby_sort_tech_article.pdf

Venko
ASKER CERTIFIED SOLUTION
Avatar of rvmsg
rvmsg

Link to home
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
Start Free Trial
SOLUTION
Avatar of Guy Hengel [angelIII / a3]
Guy Hengel [angelIII / a3]
Flag of Luxembourg image

Link to home
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
Start Free Trial
Avatar of chaos_hooi

ASKER

Thank you all for your answers and opinions.