sql >> Base de Datos >  >> RDS >> Mysql

MySQL join:ordenar los resultados a través de otra tabla PHP

Necesitas usar un simple 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

Salida:

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

Ver este SQLFiddle