如何通过mysql中的子查询排序

时间:2017-05-01 10:56:33

标签: mysql sql-order-by

我有这样的查询。

select * 
from tbl_post where id IN (select post_id from tbl_front_post 
where section = 'shrestha' order by id desc)`

现在我想根据id的{​​{1}}订购。

1 个答案:

答案 0 :(得分:0)

您必须先加入两个表,然后才能根据tbl_front_post

进行订购
select tbl_post.* 
from tbl_post 
    left join tbl_front_post on tbl_front_post .post_id = tbl_post.id 
where id IN (select post_id from tbl_front_post where section = 'shrestha') 
oreder by tbl_front_post.id