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

MySQL join - ordinamento dei risultati tramite un'altra tabella PHP

Devi usare un semplice JOIN

SELECT a.item_name, a.dish_id, b.sort
    FROM item_names AS a 
    JOIN link_extras AS b 
      ON a.dish_id = b.dish_id
   WHERE menu_id = 1
    AND section_id = 2
       GROUP BY b.dish_id
ORDER BY b.sort

Uscita:

| ITEM_NAME | DISH_ID | SORT |
------------------------------
|      Fish |      24 |    0 |
|     Chips |      27 |    1 |
|       Pie |      23 |    2 |
|    Onions |      26 |    3 |

Guarda questo SQLFiddle