Subject | Re: Master-Detail query help, please... :) |
---|---|
Author | Svein Erling Tysvær |
Post date | 2005-09-30T08:33:56Z |
Hmm, I doubt this is quicker to return the full data set, but may be
quicker to return the first few records:
SELECT M.*
FROM TableMaster M
INNER JOIN TableChild C ON M.MID = C.MID
WHERE C.SomeValue IN (A, B)
AND NOT EXISTS(SELECT * FROM TableChild C2
WHERE M.MID = C2.MID
AND C2.SomeValue < C.SomeValue)
i.e. simply move the DISTINCT from the SELECT clause to the WHERE clause.
But a better approach would of course be to return fewer records in
the first place, a DISTINCT that appears slow indicates that you
select a larger result set than would normally be appropriate for
anything but batch processing (or that I'm not quite understanding the
problem).
HTH,
Set
quicker to return the first few records:
SELECT M.*
FROM TableMaster M
INNER JOIN TableChild C ON M.MID = C.MID
WHERE C.SomeValue IN (A, B)
AND NOT EXISTS(SELECT * FROM TableChild C2
WHERE M.MID = C2.MID
AND C2.SomeValue < C.SomeValue)
i.e. simply move the DISTINCT from the SELECT clause to the WHERE clause.
But a better approach would of course be to return fewer records in
the first place, a DISTINCT that appears slow indicates that you
select a larger result set than would normally be appropriate for
anything but batch processing (or that I'm not quite understanding the
problem).
HTH,
Set
--- In firebird-support@yahoogroups.com, "Greg At ACD" wrote:
> --- In firebird-support@yahoogroups.com, hobbit wrote:
> >
> > SELECT distinct(M.*)
> > FROM TableChild C
> > JOIN TableMaster M ON M.MID = C.MID
> > WHERE C.SomeValue IN (A, B)
> >
> > HTH
> > Gary
>
> Thx, Gary!
>
> The problem with SELECT distinct(M.*) is that it is very slow since
> all columns in M will be considered when evaluating distinctness (is
> that even a word??).
>
> If I could do
> SELECT distinct(M.MID), M.*
> then we might be OK, but DISTINCT always works on the full set of
> data...
>
> Greg