我目前正在对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的列,我想将价格最低的价目表加入查询的结果中。

最佳答案

   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

关于mysql - 订购联接数据,我们在Stack Overflow上找到一个类似的问题:https://stackoverflow.com/questions/15171856/

10-13 07:31