Subject Re: Questions about SELECT DISTINCT *
Author robert_difalco
--- In firebird-support@yahoogroups.com, Svein Erling Tysvær
<svein.erling.tysvaer@...> wrote:
> >
> > SELECT * FROM Table A WHERE A.uid IN
> > SELECT DISTINCT uid FROM Table [JOINS][WHERE];
> >
>
> Yup, my first thought was "What a lousy idea, this won't even get him
> the right result"! If RowA and RowB have the same UID, then both will
> match the subselect and hence be returned. I cannot even think of a
> case where the DISTINCT word of 'IN (SELECT DISTINCT...)' makes any
> difference.

I think you are missing the JOINS. Think of a JOIN say on a Links
table that creates a tree structure. Believe it or not, the query
above performs more efficiently that without the subquery because of
the DISTINCT.

R.