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
 General SQL Server Forums
 New to SQL Server Programming
 flat table hierarchies

Author  Topic 

lemondash
Posting Yak Master

159 Posts

Posted - 2009-08-25 : 10:30:08
I have a flat table which has three colunms and built in a hierarchie format. The three colunms ID, MID, Displayname. What i want to try and do is return the whole list. The MID colunm is the child of the ID colunm. I would like to return the results with ID, and a count(*) of the child nodes and also return the parent nodes even if they have no children. I have tried a self join but it only returns parents that have child.

any help would be great

lionofdezert
Aged Yak Warrior

885 Posts

Posted - 2009-08-25 : 10:39:30
Use recursive CTE like ...
http://www.sqlservercurry.com/2009/06/simple-family-tree-query-using.html




--------------------------------------
http://connectsql.blogspot.com/
Go to Top of Page
   

- Advertisement -