首页 诗词 字典 板报 句子 名言 友答 励志 学校 网站地图
当前位置: 首页 > 教程频道 > 数据库 > SQL Server >

对union all中的每个查询分别排序的有关问题

2012-02-23 
对union all中的每个查询分别排序的问题我现在有两个表,结构完全相同,我想要把两个表满足条件的数据都检索

对union all中的每个查询分别排序的问题
我现在有两个表,结构完全相同,我想要把两个表满足条件的数据都检索出来,并且检索出来的数据不要混在一起。先是表1的数据,再是表2的数据。另外,对这两个表检索的数据的排序条件也不一样,要分别排序。
我写成下面的形式,会有错误。
select   a,b,c   from   tablex   where   ...   order   by   a
union   all
select   a,b,c   from   tabley   where   ...   order   by   b,c
改成下面的形式,还是有错误
select   *   from(select   a,b,c   from   tablex   where   ...   order   by   a)m
union   all
select   *   from(select   a,b,c   from   tabley   where   ...   order   by   b,c)n

我使用的数据库是sql   server2005,不知道这个语句应该怎么写!
求求各位大侠帮忙啦!


[解决办法]
try

select * from(select TOP 100 Percent a,b,c from tablex where ... order by a)m
union all
select * from(select TOP 100 Percent a,b,c from tabley where ... order by b,c)n

热点排行