订购加入的数据

时间:2013-03-02 07:11:32

标签: mysql doctrine-orm

我目前正在3个表中执行以下查询; handsetdealtariff

SELECT
    h.*, d.*, t.* FROM handset h
LEFT JOIN deal d ON h.id = d.handset_id
LEFT JOIN tariff t ON d.tariff_id = t.id
ORDER BY
    h.popularity
DESC LIMIT 10

“关税”表格中有一个名为price的列,我想以最低价格加入所查询结果的关税。

1 个答案:

答案 0 :(得分:1)

   SELECT
   h.*, d.*, t.* FROM handset h
   LEFT JOIN deal d ON h.id = d.handset_id
   LEFT JOIN tariff t ON d.tariff_id = t.id
   where t.price=(select min(price) from tariff)
   ORDER BY
   h.popularity
   DESC LIMIT 10