Recursive CTE hiearchy snowflake -- join/ expand outward (columns) instead of rows?
0
votes
0
answers
268
views
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?
Asked by user45867
(1739 rep)
Mar 14, 2024, 11:22 PM