Return all nodes in many-to-many hierarchal tree
问题 Similar to this question: How do I query for all the nodes between two nodes in a tree? But I do not have a closure (flattened) table, a child can have many parents, and ID traversal is not necessarily in order. There is no limit to the nesting depth. Assume a circular reference is impossible... I would like to return all rows required to traverse the hierarchy. Assume the following table: ParentID ID RowNumber(Reference) 1 2 1 2 4 2 4 3 3 3 5 4 1 6 5 6 7 6 2 8 7 3 9 8 1 8 9 6 8 10 Given 1