I have a table that stores relationships like this:
ParentName ParentID ChildName ChildId
-------------------------------------
Name1 Guid NameA Guid
Name2 Guid NameB Guid
Name3 Guid NameC Guid
NameA Guid NameY Guid
NameB Guid NameX Guid
NameC Guid NameZ Guid
NameY Guid Name1A Guid
My goal is to retrieve data stacked in way that no matter far down the hierarchy, the child columns shows who the top most parent is.
I know it's a recursive CTE, but I don't know how to write the recursive join in the query back to the anchor without breaking the max number of recursion. Parent query has 78 records using a WHERE
clause, but total levels shouldn't be more than 4 or 5. The parent can have multiple children.