码迷,mamicode.com
首页 > 数据库 > 详细

SQL Server 中关于EXCEPT和INTERSECT的用法

时间:2015-11-22 11:21:20      阅读:179      评论:0      收藏:0      [点我收藏+]

标签:

EXCEPT是指在第一个集合中存在,但是不存在于第二个集合中的数据。

INTERSECT是指在两个集合中都存在的数据。

 

create table t1(id int,mark char(2))
go
create table t2(id int,mark char(2))
go
insert into t1
    select 1,t1 union all
    select 2,t2 union all
    select 3,t3 union all
    select 4,t4
go
insert into t2
    select 2,t2 union all
    select 3,m3 union all
    select 5,m5 union all
    select 6,t6
go
select * from t1
EXCEPT
select * from t2
go
select * from t1
INTERSECT
select * from t2
go

--EXCEPT结果集为
--1    t1
--3    t3
--4    t4

--INTERSECT结果集为
--2    t2

 

SQL Server 中关于EXCEPT和INTERSECT的用法

标签:

原文地址:http://www.cnblogs.com/mc67/p/4985470.html

(0)
(0)
   
举报
评论 一句话评论(0
登录后才能评论!
© 2014 mamicode.com 版权所有  联系我们:gaon5@hotmail.com
迷上了代码!