I have a table(lets name it HEIRARCHY_TABLE ) in this format representing hierarchical data where a tree is stored in this format.
HEIRARCHY_TABLE (parent_name ,parent_id ,child_name ,child_id)
Sample Data in HEIRARCHY_TABLE:-
-------------------------------------------
parent_name |parent_id |child_name |child_id
--------------------------------------------
parent_1 | parent_1_id | leaf_node | leaf_node_id1
parent_2 | parent_2_id | parent_1 | parent_1_id
the above scenario is showing data for a case where parent_2->parent_1->leaf_node where -> representing "is parent of " relation-ship.
I need to query this table and get a result like this for all leaf nodes. Result:-
leaf_node | parent_1 | parent_2 | parent_3 |parent_4 | parent_5 |parent_6 | parent_7
and if for suppose a leaf node has only two parents then i require the rest of the parent values to be null. i.e..,if it has only 5 parents.then parent_6 and parent_7 should be null. Note :- the above table contains multiple trees.hence it contain multiple roots.I need data for all the trees available in this table in this format.the maximum level in all the trees is 7 only.