Subject Re: [ib-support] Re: Optimising an SQL Query Help
Author Svein Erling Tysvær
Hi Colin,
from your original question (asked on Sunday, but I don't see any
answers) it doesn't seem to matter how many ObjectDs have status < 8,
just if there are any. So I would simply use something like

SELECT <WhateverYouWant>
FROM ObjectA
WHERE NOT EXISTS (
Select 1
FROM ObjectD
INNER JOIN ObjectC ON (ObjectD.ID = ObjectC.ID)
INNER JOIN ObjectB ON (ObjectC.ID = ObjectB.ID)
WHERE (
(ObjectB.Id = ObjectA.Id) AND (ObjectD.Status < 8))

EXISTS could be considerably faster than a COUNT.

HTH,
Set