Entity
---------
ID
TypeAID
TypeBID
TypeAID
and TypeBID
are nullable fields where row can have one, both or none values entered, and both IDs
are pointing to same table Entity.ID
(self reference).
Is there any way to go recursive through 3 level deep structure and get flat structure of parent -> child
, parent -> grandchild
, child -> grandchild
relations?
This is example where first table is normal hierarchy and second is desired flat output.
Data:
Row ID TypeAID TypeBID
1 A NULL NULL
2 B NULL NULL
3 C A NULL
4 D B C
5 E NULL C
Desired result:
Row Parent Child
1 A C
2 A D
3 A E
4 B D
5 C D
6 C E