无法弄清楚为什么嵌套的select语句中的ORDER BY不起作用...例如:
正常的选择顺序by语句可以正常工作:
select id from posts where zid=5 order by id desc;
但嵌套的select order by statement不起作用?:
select id from posts where zid in (select id from zids where qid=57 order by id desc);
不允许吗?它不会产生任何错误,但会改变ASC& DESC没有任何改变......
答案 0 :(得分:2)
是不允许的?
不,它不是,而且根本不需要对嵌套结果集进行排序。您应该在外部查询中使用order by
,例如
select id from posts
where zid in (select id from zids where qid=57)
order by id desc;
同样,您可以考虑使用JOIN
查询替换现有查询,例如
select id from posts
JOIN zids ON posts.zid = zids.id
where zids.qid=57
order by zids.id desc;