有一个mysql查询我希望能够从第二个表运行订单

时间:2014-02-05 04:30:15

标签: mysql mysqli sql-order-by

SELECT * 
FROM app_detailsvvv as dtable 
WHERE primaryGenreName='".$ov['title']."'
  AND composed='1' AND 
  (SELECT COUNT(*) as c 
   FROM new_apps 
   WHERE trackId=dtable.trackId AND top>0) > 0 
ORDER BY top ASC

我想在这里做的是ORDER BY表格new_apps而不是app_detailsvvv,因为它甚至没有顶级字段,怎么做?

1 个答案:

答案 0 :(得分:0)

为此使用INNER JOIN。这将是您的查询:

SELECT dtable.* FROM app_detailsvvv as dtable 
INNER JOIN new_apps ON new_apps.trackId=dtable.trackId
WHERE primaryGenreName='".$ov['title']."'
    AND composed='1' AND
    (SELECT COUNT(*) as c
    FROM new_apps
    WHERE trackId=dtable.trackId AND top>0) > 0
ORDER BY new_apps.top ASC