有一年的表,如下
rec_0101 / rec_0102 / rec_0103
id | 账号 | 内容
---------------------
select * from rec_0101 where 账号='hello' order by id desc
union all
select * from rec_0102 where 账号='hello' order by id desc
union all
select * from rec_0103 where 账号='hello' order by id desc
我想查多天,倒序,但是 报错。。如何是好
------解决方案--------------------
select * from (
select * from rec_0101 where 账号='hello'
union all
select * from rec_0102 where 账号='hello'
union all
select * from rec_0103 where 账号='hello' )a
order by id desc
------解决方案--------------------
UNION /UNION ALL/EXCEPT/INTECEPT中,只能有一个order by
------解决方案--------------------
试试这个:
select * from rec_0101 where 账号='hello'
union all
select * from rec_0102 where 账号='hello'
union all
select * from rec_0103 where 账号='hello' order by id desc
------解决方案--------------------
with ta as (select * from rec_0101 where 账号='hello'
union all
select * from rec_0102 where 账号='hello'
union all
select * from rec_0103 where 账号='hello' )
select * from ta order by id desc
------解决方案--------------------
看下UNION的定义就知道啦,只有最后一句话里能放ORDER BY,前面的都不能放的额
------解决方案--------------------
微软认为 集合 没有排序
------解决方案--------------------
这是关系数据库的定义,不是微软自创的
------解决方案--------------------
在子查询,派生表或者视图中,除非指定了top ,不能使用order by