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

union all 有关问题

2012-02-12 
union all 问题1。为什么搜索6-8条记录,而sql语句无记录,是不是notexists只执行where语句:selecttop3*fromp

union all 问题
1。为什么搜索6-8条记录,而sql语句无记录,是不是not   exists只执行where语句:
select   top   3   *   from   person   A
where   not   exists   (select   top   5   *   from   person     B   where   A.person_id=B.person_id)
2。为什么union   all   无法跟order   by   运行,但作为一个表来执行却可以,
如:
select   id   from
(
select   top   5     id   from   person   order   by   id  
  union   all  
select   top   8     id   from   person   order   by   id  
)   C
可以运行,但下个语句却无法运行
select   top   5     id   from   person   order   by   id  
  union   all  
select   top   8     id   from   person   order   by   id  


[解决办法]
select top 3 * from person A
where not exists (select top 5 * from person B where A.person_id=B.person_id)
是什么意思啊? 你的not exists理解有问题

[解决办法]
select top 5 id from person --要去掉這個order by id
union all
select top 8 id from person order by id
[解决办法]
1、select top 3 * from (select top 8 * from person order by id asc) b order by id desc
2、第一个order by 不要
[解决办法]
select id from
(
select top 5 id from person order by id
union all
select top 8 id from person order by id
) C

是把()里当前一作表来处理,

热点排行