declare @tableA table (Name int,Source varchar(1)) insert into @tableA select 1,'a' union all select 2,'b' union all select 3,'c'declare @TableB table (Name int,source varchar(1)) insert into @TableB select 1,'a' union all select 4,'c' union all select 5,'d'select b.* from @tableA a full join @TableB b on a.Name=b.Name and a.Source=b.Source where a.Name is null /* Name source ----------- ------ 4 c 5 d */
declare @表A table ([Name] varchar(50),[Source] varchar(50)) insert into @表A select 'XXX','aaa' union all select 'aaa','bbb' union all select 'ccc','ddd' declare @表B table ([Name] varchar(20),[Source] varchar(20)) insert into @表B select 'ccc','ddd' union all select 'aaa','bbb' union all select 'ggg','hhh' ----找出TableB里面 Name和Source的组合 在TableA里面不存在 的数据 select b.* from @表A a full join @表B b on a.Name=b.Name and a.Source=b.Source where a.Name is null Name Source -------------------- -------------------- ggg hhh(1 行受影响)
declare @tableA table (Name int,Source varchar(1))
insert into @tableA
select 1,'a' union all
select 2,'b' union all
select 3,'c'declare @TableB table (Name int,source varchar(1))
insert into @TableB
select 1,'a' union all
select 4,'c' union all
select 5,'d'select b.* from @tableA a full join
@TableB b on a.Name=b.Name and a.Source=b.Source
where a.Name is null
/*
Name source
----------- ------
4 c
5 d
*/
insert into @表A
select 'XXX','aaa' union all
select 'aaa','bbb' union all
select 'ccc','ddd' declare @表B table ([Name] varchar(20),[Source] varchar(20))
insert into @表B
select 'ccc','ddd' union all
select 'aaa','bbb' union all
select 'ggg','hhh' ----找出TableB里面 Name和Source的组合 在TableA里面不存在 的数据
select b.* from @表A a full join @表B b on a.Name=b.Name and a.Source=b.Source where a.Name is null
Name Source
-------------------- --------------------
ggg hhh(1 行受影响)