union all 中 使用 order by 不起作用

码上中国博客 发布于 2017/03/09 13:41
阅读 482
收藏 0

【开源中国 APP 全新上线】“动弹” 回归、集成大模型对话、畅读技术报告”

我想单独查出要置顶的部分数据(这部分数据其实只有一条数据),然后合并查询不是置顶的数据(按照创建时间排序),发现使用下面的SQL排序不起作用,请问如何解决? 

SQL如下:

select * from usermsg_info where msgType =5 and othersMsg='top' 
		union all
select * from usermsg_info where msgType =5 and othersMsg !='top' order by createTime desc

 

加载中
0
万人中央我是光
万人中央我是光

select * from(select... union all select ..) order by createTime desc

码上中国博客
码上中国博客
你这样就没法置顶union 前查询出来的结果了,我的本意是union前的SQL结果不排序(因为只有一条,且要求这一条位于整个SQL结果的第一条位置),union all后面的数据才排序。
0
OSCHINA
登录后可查看更多优质内容
返回顶部
顶部