Sudipa writes "Hi,I wish to do a recursive join till a given criteria is achieved. How should I write the SQL?For example:I have a table which has a tree structure as Parent Level 0 Child Level 1 Child Level 2 Child Level 3I want to get the tree thru an SQL query. The Records in TreeTable are as below :MemId ParentId Level GroupId------ -------- ----- -------P1 0 1 1C11 P1 2 1C12 C11 3 1C13 C12 4 1P2 0 1 2C21 P2 2 2C22 C21 3 2
Now given MemId as C22 I should be able to get back the Hierarchy back to its parent i.e.P2 0 1 2C21 P2 2 2C22 C21 3 2
Or given MemId as C13 I should be able to get back the Hierarchy back to its parent i.e.P1 0 1 1C11 P1 2 1C12 C11 3 1C13 C12 4 1
Please note that there is a common GroupId for a Hierarchy.Let me know how I can achieve the above results thru a Single SQL query.I should be able to run this Query in the Query Analyzer for SQL Server 2005.I was thinking of doing a recursive join till ParentId = '0' for a given GroupId.Don't know the syntax.Please reply ASAP.It's urgent.Regards,Sudipa"