mysql - Two separate joins on the same query -
i have query find duplicates in table:
select sofferenze.id_soff, sofferenze.descrizione sofferenze inner join ( select descrizione sofferenze group descrizione having count( id ) >1 )dup on sofferenze.descrizione = dup.descrizione order descrizione asc
it works charm , gives me duplicated rows. have query starting sofferenze.id_soff give me value in table:
select cod_fisc anagrafiche join `rischiatura` on anagrafiche.id_ndg = rischiatura.id_ndg id_ogg = 'sf000000012' , id_ruolo = 'ru010000002'
actually second query run each row returned first query replacing in line where id_ogg='sf000000012'
value 'sf000000012' value sofferenze.id_soff returned first query.
this code not efficient because runs several times second query. there option can merge 2 queries?
why not combine sub-query?
select cod_fisc anagrafiche join `rischiatura` on anagrafiche.id_ndg = rischiatura.id_ndg id_ogg in (select x.id_soff sofferenze x x.descrizione in ( select ix.descrizione sofferenze ix group ix.descrizione having count( * ) >1 )) , id_ruolo = 'ru010000002'
Comments
Post a Comment