数据表TA ( id ) {1,2,4,5}

数据表TB ( id ) {2,3,5,6,7}

=========================================

1.并集 union all -->得到 左表有的 加上 右表有的:

select id from ta
union all
select id from tb;

-----------------------------------------------------

ID
1
2
4
5
2
3
5
6
7

=========================================

2.并集 union -->得到 左表有的 加上 右表有的,然后剃重:

select id from ta
union
select id from tb;

-----------------------------------------------------

ID
1
2
3
4
5
6
7

=========================================

3.交集 intersect -->得到 左表和右表同时有的:

select id from ta
intersect
select id from tb;

-----------------------------------------------------

ID
2
5

=========================================

4.差集 minus -->得到 左表有 但是右表没有的:

select id from ta
minus
select id from tb;

-----------------------------------------------------

ID
1
4

=========================================

 

 posted on 2011-11-30 15:15  Lucien.Bao  阅读(403)  评论(0编辑  收藏  举报