I’m able to generate a hierarchy with a recursive CTE but I have always made use of an anchor… a top level record with some top level indicator (parentID IS NULL). I would like to build a hierarchy that doesn’t necessarily have a defined anchor. I have a many to many reference table with a parentID and a childID. Any parent can be a child and vice versa (avoiding circular reference of course). I’m thinking this would be more of a bottom-up approach as opposed to top-down. Thoughts?
Share
You can’t build a recursive query using CTE without having at least one anchor member and one recursive member.
While a recursive CTE is used to generate a hierarchy , the problem in this case is that the data in the table does not represent a hierarchy, for hierarchy is a type of a directed acyclic graph , therefore it must have one element (the hierarch ) which is superior to all of the other elements.