Home Page for the TeradataForum

Archives of the TeradataForum

Message Posted: Mon, 03 Dec 2007 @ 23:04:52 GMT

  <Prev Next>  
Next> Last>>  

Subj:   Parent Child Relationship
From:   Mohd Suhail

Hi All,

I have a table that contains two columns: parent column and child column. The data in the table represents the structure of a tree with a root on top and base elements in the bottom. Example:

     parent   Child

     A          B
     A          C
     B          D
     C          E
     C          F
     E          G

The desired output from the above mentioned data should be a list of all possible routes from the root to the bottom. For example, the output for the above example will be

     parent  child1  child2  child3

     A         B        D       ?
     A         C        E       G
     A         C        F       ?

Now I know that this can easily be done by performing a self join three times over parent=child. But this would be a hard coded solution. Please suggest me a generalised way to get the desired output for any levels of the tree. As a restriction, I am instructed not to use procedures or cursors.


  <Prev Next>  
Next> Last>>  
  Top Home Privacy Feedback  
Copyright for the TeradataForum (TDATA-L), Manta BlueSky    
Copyright 2016 - All Rights Reserved    
Last Modified: 15 Jun 2023