Subject Re: [ib-support] Query Results problem
Author Svein Erling Tysvaer
Hi George,

At 11:19 09.06.2003 -0500, you wrote:
> >you're hiding things from us.
>
>Trying not to, but being in the medical industry makes it hard for me to
>release
>actual statements.

Yup, since I work in a cancer registry, I'm likely to use good ideas
appearing on this list!

>WHERE
> A.PK = :ParameterizedPK AND
> D.YETANOTHERFIELD IS NULL AND
> E.YETANOTHERFIELD IS NULL

this may be enough for us, at least considering that your original query
contained

>FROM
> TALBEA A LEFT JOIN TABLEB B ON (A.FK1 = B.PK)
> LEFT JOIN TABLEB C ON (A.FK2 = C.PK)
> LEFT JOIN TABLEC D ON (A.FK3 = D.PK)
> LEFT JOIN TABLEC E ON (A.FK4 = E.PK)

In your join you say that Firebird is to return records of A, whether or
not there is a matching record of D and E - and then in your WHERE-clause
you say that you should restrict returning to certain values of the same
tables. I think that in a LEFT [OUTER] JOIN, the only proper way to
restrict records of tables at the right side of the join is within the JOIN
criteria, not in the WHERE clause (I think I read it in some Interbase 5.6
documentation). Try changing your query to something like:

FROM
TALBEA A LEFT JOIN TABLEB B ON (A.FK1 = B.PK)
LEFT JOIN TABLEB C ON (A.FK2 = C.PK)
LEFT JOIN TABLEC D ON (A.FK3 = D.PK AND D.YETANOTHERFIELD IS NULL )
LEFT JOIN TABLEC E ON (A.FK4 = E.PK AND E.YETANOTHERFIELD IS NULL )
WHERE
A.PK = :ParameterizedPK

HTH,
Set