mysql union order by 子查询排序不生效

其实这么写理论上是对的,不少博客教程都是这样子写的。。优化

select * from (SELECT * FROM article WHERE is_top=0 ORDER BY id DESC) as t1排序

union教程

select * from (SELECT * FROM article WHERE is_top=1 ORDER BY start_time desc) as t2博客

 

而后仍是发现子查询的排序无效,尴尬,后来才发现若是order by 不带limit,会被优化器干掉,致使语句就是:it

select * from (SELECT * FROM article WHERE is_top=0 ) as t1io

unionselect

select * from (SELECT * FROM article WHERE is_top=1) as t2nio

 

解决方案:im

select * from (SELECT * FROM article WHERE is_top=0 ORDER BY id DESC limit 999999) as t1查询

union

select * from (SELECT * FROM article WHERE is_top=1 ORDER BY start_time desc limit 999999) as t2

相关文章
相关标签/搜索