当我在 SQL 中执行 except 和 union 语句时,我看到了一种奇怪的行为。
我有两张桌子
Select * from #old
数据看起来像这样
oid1 oid2 co
1 11 1
2 22 1
3 33 1
4 55 1
Select * from #new
nid1 nid2 co
1 11 3
2 22 1
3 33 1
4 44 1
4 55 1
这是我的最后一个查询
Select * from #old
except
Select * from #new
union all
Select * from #new
except
Select * from #old
并给出这些记录
oid1 oid2 co
1 11 3
4 44 1
我的问题是..从第一个 except 子句中不应该有另一行:
Select * from #old
except
Select * from #new
这是
oid1 oid2 co
1 11 1
最终查询不应该有 3 行而不是只有 2 行,因为并非所有列都相同。