Oracle FAQ | Your Portal to the Oracle Knowledge Grid |
Home -> Community -> Usenet -> c.d.o.server -> Re: Why DISTINCT is costly?
Robert Klemme wrote:
> sim wrote:
> > In most cases it's better to use a group by than distinct. That should
> > decrease the cost of your queries.
>
> Why? The task of identifying duplicates remains the same...
>
> robert
Right, it doesn't reduce the cost. I always suggest replacing
SELECT DISTINCT x ...
with
SELECT x,COUNT(*) ... GROUP BY x ;
especially for adhoc queries. Then at least you get back some information about the duplicates.
For production, you can either refine your query to get back unique information (preferred IMHO), or ignore the extras based on an informed choice.
Ed Received on Mon Sep 12 2005 - 08:41:50 CDT