Subject | Re: Efficiently find records from a self join without children records or a field=1 |
---|---|
Author | Bhavbhuti Nathwani |
Post date | 2009-06-21T19:44:46Z |
Hi all
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
Thanks and regards
Bhavbhuti
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
Thanks and regards
Bhavbhuti
--- In firebird-support@yahoogroups.com, "Bhavbhuti Nathwani" <venussoftop@...> wrote:
>
> Hi all
>
> I have a self-joined table to represent a hierarchical structure. Now I want a list of records that do not have children records (leaf nodes) or specifically records that have a field with a value of 1 (even though there are children recoards for them)
>
> Thanks and regards.
>
> Bhavbhuti
>