0

I have the following (simplified) table:

group_id member_id
1 2
2 3
3 4
5 4
6 4
7 8

It's to manage groups and their members, while a group can also be the member of a group. What I want is to get all groups where a specific ID is a member of, either directly or via another group.

So for the example above I would want to have all groups that the member with the ID 4 is a member of and the result should be (without the brackets):

(sorry for the broken 2nd table, it always look good in the preview)

| group_id |

| 1 (via group 2)| | 2 (via group 3)| |3 (directly)| |5 (directly)| |6 (directly|

I am honestly a bit lost right now and I am not sure if researching recursive queries is the right path or if there's an easier solution.

Thanks for your help.

Core_F
  • 3,372
  • 3
  • 30
  • 53

0 Answers0