I have a table of parts and sub-parts where each record contains the primary part for that record along with its ChildPart.
Part - ChildPart
A - B
A - C
A - D
C - F
C - Z
F - R
Z - R
Q - B
Q - C
So for the example above, part A
has 7 total descendants (B, C, D, F, Z, R, R
). A parent part can have multiple children and a child part can belong to more than 1 parent; notice that part B
is used for both A
and Q
.
How can I efficiently show all the child parts of a given parent part just using joins and not using SQL cursors or loops? The hierarchical tree could theoretically be infinitely deep.