I'm doing a dependency mapping explosion (like parts explosion).
I did a typical recursive CTE with a union all.
It looks like
with CTE as
( select abc from myTable where start_point = X
union all
select abc from CTE join myTable where myTable.parent = CTE.child
)
select * from CTE
... However this ends up with a list like
Root -> Child 1
Root -> Child 2
Root -> Child 3
Child 1-> 1 Grandchild 1
Child 2 -> 2 Grandchild 1
Child 2 -> 2 Grandchild 2
I'd prefer it looked like
Root -> Child 1 > Grandchild 1
Root -> Child 2 - >2 Grandchild 1
Root -> Child 2 -> 2 Grandchild 2
Root -> Child 3
It's like ... I need a recursive join, not a recursive union -- but when I replace the union with a join, I can't quite get it to work. Any ideas?
PIVOT
to transform your results of the recursive CTE into a columnar format akin to your goal.