Link to home
Start Free TrialLog in
Avatar of Webbo_1980
Webbo_1980

asked on

How do i do an inner/ recurrsive join on a single table?

How do I join a table on its self i.e. lets say for example that I have a table with the following schema i.e.

Table 1, with columns ID, Name, ParentId and lets say ParentId was a forgeign key for a matching row in the same table, how would I get all rows returned with all rows containing parented in order so e.g.

1, aaa, null
2, bbb,1
3,ccc,2
4,ddd,null
5,eee,4

And lets say i made a query which said i want all rows with an id of 1 and all child rows from 1 whether there child or child of child,or child of child of child and so on,  .

So e.g. lets say i wanted all row related to id of . So in this instance i'd get the following returned in this order i.e.

1, aaa, null  ---> Parent
     2, bbb,1 ----> Child
         3,ccc,2 ----> Child of child with parent od 1
           

Thanks
Webbo
Avatar of Om Prakash
Om Prakash
Flag of India image

Please check the following tutorial on recursive queries:
http://www.vbforums.com/showthread.php?t=366078

This article contains same information that you need
ASKER CERTIFIED SOLUTION
Avatar of Paul_Harris_Fusion
Paul_Harris_Fusion
Flag of United Kingdom of Great Britain and Northern Ireland image

Link to home
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
Start Free Trial