Subject Re: Master-Detail query help, please... :)
Author Greg At ACD
--- In firebird-support@yahoogroups.com, Ivan C Cruz <ivancruz@c...>
wrote:
> Greg At ACD escreveu:
>
> >First try:
> >
> >SELECT M.*
> >FROM TableMaster M
> > INNER JOIN TableChild C ON M.MID = C.MID
> >WHERE C.SomeValue IN (A, B)
> >
> >
> >
> I'm not completely sure but, I believe what you want is
> simple that:
>
> SELECT M.*
> FROM TableMaster M
> WHERE Exists ( SELECT *
> FROM TableChild C
> WHERE M.MID = C.MID
> AND C.SomeValue IN (A, B) )
>
>
> Ivan.

That does work... the only problem is that TableMaster will be table
scanned (PLAN (M NATURAL) ...), which is something to avoid since
there are a lot of records in TableMaster.

The idea hopefully would be avoid the table scan on the TableMaster
table by somehow getting the resulting list of MIDs from the child,
then joining this result to the master table to get the actual data.
That's where I'm struggling... :)

Thx for the thought, tho... I do appreciate it :)

Greg