Mysql one to many relationship (bring the information at the same time)


If I have a relationship from one to many tables there are 5 tables the main one and the other 4 tables

If I have to bring the information of the 5 tables at the same time what would be the correct way to do it? what I did were 5 different stored procedures 4 inner join separately for the 4 table and another select from the main table it's fine or there's a better way to do it As you can see in the image, the department table is the main one

asked by Sergio Romero 09.10.2016 в 03:12

1 answer

select *
from departamento d 
inner join municipios m 
  on d.deptoID = m.deptoID
inner join ComidasTipicas ct
  on ct.deptoID = d.deptoID
  /*Aquí puedes agregar cualquier otra condición utilizando la cláusula And*/
inner join LugaresTuristicos lt
  on lt.deptoID = d.deptoID
inner join Pueblos p
  on p.deptoID = d.deptoID

Additionally I recommend that if you are going to use plural in the name of the tables, do it in all ...

answered by 11.10.2016 в 16:54