So here is the problem :
I have a table "Members" with members and their attributes (name, birthday, mail, etc.) These members may belong to groups (let's say there are 3 groups), from none to all of them. And these groups are referenced in a table ("Groups") so I can add/delete/modify them as I want.
SET()
doesn't seem to be a solution, it isn't compatible with foreign keys / reference table.
So at first, I was thinking of doing a TINYINT()
column, which I use like SET()
: 111 (7)
for all groups, 000 (0)
for none, 001 (1)
for the 1st group , 010 (2)
for the 2nd, etc. But since the names are quite complex, it's confusing, and not much more compatible with foreign keys.
I read that I should do a 3rd table "Members-Groups" with memberID and groupID to join both of my two tables, but I don't clearly understand how it work.
What I understand is that I will have a table with IDs of members and groups like this :
+----------+---------+
| memberID | groupID |
+----------+---------+
| 1 | 1 |
| 1 | 2 |
| 2 | 1 |
| 2 | 3 |
| 3 | 2 |
+----------+---------+
and combined with junction I can retrieve what I want. Is it right ? Otherwise can someone explain me how i should do ?
I precise that I'd like to have as final result (after sql request + php script) a member, his attributes and the groups he belongs to in a single row (as with SET()
), even members that doesn't belong to any group.