Subject | [ib-support] Re: Optimising an SQL Query Help |
---|---|
Author | Svein Erling Tysvær |
Post date | 2002-01-25T09:54:08Z |
Sorry if this is sent twice, it didn't seem to work in my first attempt.
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
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