您的位置:首页 > 其它

模糊查询和排序后合并查询结果集

2015-11-16 17:08 253 查看
今天需要做一个查询,当天时间按时间降序排列排在最前面,然后是其他的按时间降序排列排在当天的时间后面。

select * from
( select * from Table
where time like '2015-11-16%'
order by time desc ) a
union all select * from
(select * from Table
where id not in
( select Table.id from Table
where time like '2015-11-12%')
order by time desc ) b
limit 0,20

必须外面包一层,直接两个结果集 union 发现正常的在上面,到期的在下面,但是各自内部是无序的,也就是说union的时候是没有order by做的union,

内部的order by没有生效, 包了一层应该是产生了临时中间表,次序便固定了。
内容来自用户分享和网络整理,不保证内容的准确性,如有侵权内容,可联系管理员处理 点击这里给我发消息
标签: