Is there a better way to make this mysql query using inner join commands? -


in database have several tables "many many" relationships referencing 1 another, , way taught make queries through embedded queries.

i've been reading "many many" relationships, , how query them using "inner join" but, don't seem able find queries fit i'm looking for, , since database work big tables don't want code have performance issues.

select salones.idsalon,         salones.lat,         salones.long,         recursos.idrecurso,         recursos.recurso salones,       recursos,       salones_has_recursos salones_has_recursos.salones_idsalon=salones.idsalon    , salones_has_recursos.recursos_idrecurso=recursos.idrecurso    , recursos.idrecurso in (select idrecurso                              salones_has_recursos                              idrecurso in (select idrecurso                                                  recursos                                                  recurso = 'audiovisual'                                                 )                             ) 

i know having embedded queries performance killer, way figure how info need table. know how same result using "inner join" commands?

the resulting table should little this

this data content of tables

i'll give starter in hopes can figure out how works:

this:

select idrecurso salones_has_recursos idrecurso in (select idrecurso recursos recursos = 'audiovisual'); 

becomes:

select    s.idrecurso     salones_has_recursos s   inner join recursos r     on s.idrecurso = r.idrecurso     r.recursos = 'audiovisual'; 

i can't guarantee work sans means test, think full solution:

select     s.idsalon,     s.lat,     s.long,     r.idrecurso,     r.recurso     salones s    inner join recursos r      on s.idrecurso = r.idrecurso      , r.recursos = 'audiovisual'    inner join salones_has_recursos sr      on sr.salones_idsalon=s.idsalon      , sr.recursos_idrecurso=r.idrecurso; 

Comments

Popular posts from this blog

Django REST Framework perform_create: You cannot call `.save()` after accessing `serializer.data` -

Why does Go error when trying to marshal this JSON? -