problem when relating tables in MySql

1

Inside my mysql DB I have a table called teachers, which looks something like this.

Nombre | email | id | password ...

The problem is that I have to relate it to another call grupos , (it's to classically organize a group with its multiple teachers)

the profesores table looks something like this:

Nombre | image | id | fecha ...

normally this would be solved by putting in one of the two tables a field called grupo_id or profesores_id , the problem is that of doing one of those two things I would be limited to one in any of those, that is, I would have a group that has only one teacher, or that a teacher has only one group, which obviously does not happen in reality and I do not want that to be the case.

    
asked by Freak24 20.11.2017 в 14:09
source

1 answer

1

Create an intermediate table profesores_grupos with two fields: profesorId and grupoId . Then create relationships between the tables you have and the two fields in this table.

With that you will have several to several relationships as you want.

    
answered by 20.11.2017 / 14:13
source