Please start any new threads on our new site at https://forums.sqlteam.com. We've got lots of great SQL Server experts to answer whatever question you can come up with.

 All Forums
 SQL Server 2000 Forums
 SQL Server Development (2000)
 Childless Parents Pose Problems

Author  Topic 

uberbloke
Yak Posting Veteran

67 Posts

Posted - 2001-06-20 : 07:57:07
I have a table of parents and childs

 
uid, parentid
1, 0
2, 0
3, 1
4, 1


what I want to do is return the top level parents (ie this with parent id = 0), but ONLY those that have children, so for the table above I would see uid = 1 as it is the parent of 3 & 4, but not poor old 2 as it is child-less.

Now I have done this with the following :

select uid
from [tablename]
where parentid = 0
and uid in (select parentid from [table name])

which works (which is nice) but was wondering if there was a "better" way.



   

- Advertisement -