-1

I have a requirement where I need to sort out a data table with self referential relationship.

My Table looks something below as shown in the image. I want all the related subset records should be displayed under the parent record. Any Help?

Existing Table

|:------------------------------------------------------:| |Id....................|Color...........|.IsSubset?.....|..SubsetOf...|

|:------------------------------------------------------:|

|11111111.....|..Black..........| No................|...........................|

|234435..........|..Blue............| No.............. | ...........................|

|43657668.... |..Red............ | yes............. | 1111111111. |

|5767876....... |..Green....... | yes............. | 1111111111. |

|65876987.... | yellow........ | yes............. | 234435.......... |

|7697800....... | orange...... | yes............. | 234435.......... |

|:------------------------------------------------------:|

Expected table

|:------------------------------------------------------:| |Id....................|Color...........|.IsSubset?.....|..SubsetOf...|

|:------------------------------------------------------:|

|11111111.....|..Black..........| No................|...........................|

|43657668.... |..Red............ | yes............. | 1111111111. |

|5767876....... |..Green....... | yes............. | 1111111111. |

|234435..........|..Blue............| No.............. | ...........................|

|65876987.... | yellow........ | yes............. | 234435.......... |

|7697800....... | orange...... | yes............. | 234435.......... |

|:------------------------------------------------------:|

Tables

1 Answers1

-1

Grab all the rows that have no parent and order them. Then loop thorough each of those, recursively calling the same logic (passing in the row you are on), but this time order (and recursively call) the rows where the parent is the id from passed in row.

Beakie
  • 1,948
  • 3
  • 20
  • 46
  • Hi Beakie. Thanks for your response... My Table is a very big one and the performance will go way down if I am looping it for every parent.. – Deepika Namburi Feb 18 '22 at 13:39