Mysql
 sql >> Database >  >> RDS >> Mysql

SQL:come SELEZIONARE più tabelle e UNIRE più righe dalla stessa colonna?

Puoi unirti allo stesso tavolo più volte, devi solo dare alias diversi

SELECT painting.id, 
       painting.order, 
       painting_en.url, 
       `group`.en AS `group`, 
       TYPE.en AS type, 
       location.en AS location
FROM   painting 
       LEFT JOIN painting_en 
       USING (id) 
       LEFT JOIN id_portfolio `group` 
         ON `group`.id = painting.id_group 
       LEFT JOIN id_portfolio TYPE 
         ON TYPE.id = painting.id_type 
       LEFT JOIN id_portfolio location 
         ON location.id = painting.id_location 
WHERE  painting_en.url = '2011-name3' 
LIMIT  1