Subject Re: [firebird-support] Re: Efficiently find records from a self join without children records or a field=1
Author Milan Babuskov
Bhavbhuti Nathwani wrote:
> This is what I have created, can it be made better?
> SELECT mItems.iID, mItems.cDesc
> FROM mItems
> WHERE (mItems.iID NOT IN (SELECT DISTINCT mParent.iID
> FROM mItems mChild
> JOIN mItems mParent
> ON mParent.iID = mChild.iPID))
> OR mItems.lExcisable = 1

Try:

SELECT iID, cDecs
FROM mItems m
WHERE lExcisable = 1 OR not exists(
select 1
from mItems d
where d.iPID = m.iID)


HTH

--
Milan Babuskov
http://www.flamerobin.org
http://www.guacosoft.com