情况:
在使用暂存时,列表使用union all 合并sql数据时,第一部分暂存数据排序失效
原因:union all的优先级会比order by 的优先级更高,优先执行union all
两种方式
:
-
如果获取整个union all ,再排序,
select rest.* from (语句1 union all 语句2) rest order by rest.createtime; -
每个子集先排序,后合并
将语句1和语句2在包上一层select,
例如 select t.* from ( 语句1) t union all select m.* from (语句2) m;
希望所写的对你们有用。