有关SQL Server的简单问题。
我希望这个查询:
-- part 1
select * from table01
except
select * from table02
--
union all
-- part 2
select * from table02
except
select * from table01
会给我相同的结果集,就好像分别进行第1部分和第2部分两个部分一样。但是我只是从查询中得到两行,但从两个部分中得到两行。知道为什么会这样会很有趣吗?
Declare @t table(col1 int)
insert into @t values(1),(2)
Declare @t1 table(col1 int)
insert into @t1 values(1),(3)
1.) select * from @t
except
2.) select * from @t1
union all
3) select * from @t1
except
4) select * from @t
1 ) and 2 ) give 2
then previos result aand 3 gives 2,1,3
then again last result and 4) give 3
so final Result=3
本文收集自互联网,转载请注明来源。
如有侵权,请联系[email protected] 删除。
我来说两句