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
是把()里当前一作表来处理,