sqlserver三种数据集合运算

2.1   并集运算(UNION)

 (1)UNION ALL(不删除重复行) 

 Code:

1 SELECT empID,empName,position,degree
2 FROM Employees
3 UNION ALL
4 SELECT empID,empName,position,degree
5 FROM Sales

 (2)UNION(隐式DINSTINCT,删除重复行)

 Code:

1 SELECT empID,empName,position,degree
2 FROM Employees
3 UNION  
4 SELECT empID,empName,position,degree
5 FROM Sales

2.2 交集(INTERSECT)

 Code:

1 SELECT empID,empName,position,degree
2 FROM Employees
3 INTERSECT  
4 SELECT empID,empName,position,degree
5 FROM Sales

2.3  差集

Code:

1 SELECT empID,empName,position,degree
2 FROM Employees
3 EXCEPT  
4 SELECT empID,empName,position,degree
5 FROM Sales
posted @ 2017-07-28 17:20  桃花雪  阅读(557)  评论(0编辑  收藏  举报