SQLServer2005通过intersect,union,except和三个关键字对应交、并、差三种集合运算
他们的关系对应如下
createtablet1 (aint)
insertintot1select1unionselect2unionselect3
createtablet2 (aint)
insertintot2select3unionselect4unionselect5
go
select*fromt1unionselect*fromt2
go
/* 求表并集
1
2
3
4
5*/
select*fromt1unionallselect*fromt2
go
/*求表并集不过滤重复
1
2
3
3
4
5*/
select*fromt1exceptselect*fromt2
go
/*求t1对t2的差集
1
2*/
select*fromt1intersectselect*fromt2
go
/*求t1对t2的交集
3*/