In MySql database, I have a table user
user_id | user_name
--------+----------
1 | Joe
2 | Anna
3 | Max
Table group
group_id | group_name
---------+----------
1 | Red
2 | Blue
3 | Green
Table group_member
group_member_id | user_id | group_id
----------------+---------+---------
1 | 1 | 2
2 | 3 | 2
3 | 1 | 3
3 | 2 | 1
So ... A member of the red group is Anna, a member of the Green gorup is Joe, and members of the Blue group are Joe and max.
How to get a list of users and their groups
User | Group
------+------------
Joe | Green, Blue
Anna | Red
Max | Blue
source
share