sqlrecursiongenealogy

Select all genealogy of a father in SQL without WITH or WHILE


Is it possibile to select all childs of a parent without recursive system as WITH or WHILE?

The structure is:

Father  Child

NULL    1
1       2
1       3
2       4
3       5
4       6
6       7

I want the "childs" (all genealogy, childs of childs, etc. etc.) of 2, so I want:

4, 6, 7


Solution

  • Yes. Every recursive function has a non-recursive solution:

    Can every recursion be converted into iteration?

    Some other resources that might be helpful:

    http://www.slideshare.net/rs_rs123/removal-of-recursion

    http://www.refactoring.com/catalog/replaceRecursionWithIteration.html