In MySQL, I have a table called "maintenance" and another called "technicians" where a maintenance can be done by one or many technicians... To do this, there is the commun way of creating a table Maintenance_Technician, containing records with the couple (mnt_id, tech_id).. than, to get data, we have to make a double inner join...
Here is the query (MT_Mnt_Id and MT_Tech_Id) are fields of the intermediate table "Maintenance_Technicians"
SELECT * FROM Maintenance INNER JOIN Maintenance_Technicien ON Mnt_Id=MT_Mnt_Id INNER JOIN Technicians ON Tech_Id=MT_Tech_Id
I wonder if this is the best way to do it, if I have a maximum of 7 technicians to do each maintenance!
There are many other non commun ways such as :
1- Having 7 fields in the "maintenance" table, one for each technician, and letting null the unused fields (when less that 7 technicians make the intervention)
in this case the select query would be :
SELECT * FROM Maintenance INNER JOIN Technicians ON (Mnt_Tech1_Id=Tech_Id OR Mnt_Tech2_Id=Tech_Id OR Mnt_Tech3_Id=Tech_Id OR Mnt_Tech4_Id=Tech_Id etc..)
2- To store the ids of the technicians in one field, each one written between ';' for example ";5;10;25;". The select query would be like this :
SELECT * FROM Maintenance INNER JOIN Technicians ON (instr(Mnt_Tech_Ids, concat(';', Tech_Id , ';')))
I like the second non commun way, but I am not sure if those are better than the commun way or not.. can you help me take decision? Is there any better solution?
Thanks in advance