SQLServer数据集合的交、并、差三种集合运

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*/

本文转载http://www.cnblogs.com/AllUserBegin/p/3513082.html

 

posted on 2014-01-10 09:13  riky1989  阅读(172)  评论(0)    收藏  举报

导航