--好像是我理解错了,楼主是这个意思吧? --a表中的a列和b表的b列相同的数据 select * from a where exists(select 1 from b where b=a.a)--查a表中的a列和b表的b列不同的数据 select * from a where not exists(select 1 from b where b=a.a)
--测试--测试数据 create table a(a varchar(10)) insert a select 'a' union all select 'a' union all select 'a' union all select 'a' union all select 'a' union all select 'as' union all select 'ab' union all select 'ac' union all select 'ad' union all select 'aa'create table b(b varchar(10)) insert b select 'a' union all select 'a' union all select 'ab' union all select 'ac' union all select 'ad' union all select 'ae' go--a表中的a列和b表的b列相同的数据 select * from a where exists(select 1 from b where b=a.a)--查a表中的a列和b表的b列不同的数据 select * from a where not exists(select 1 from b where b=a.a) go--删除测试 drop table a,b/*--测试结果--a表中的a列和b表的b列相同的数据 a ---------- a a a a a ab ac ad(所影响的行数为 8 行) --查a表中的a列和b表的b列不同的数据 a ---------- as aa(所影响的行数为 2 行) --*/
--a表中的a列和b表的b列相同的数据
select *
from a
where exists(select 1 from b where b=a.a)--查a表中的a列和b表的b列不同的数据
select *
from a
where not exists(select 1 from b where b=a.a)
create table a(a varchar(10))
insert a select 'a'
union all select 'a'
union all select 'a'
union all select 'a'
union all select 'a'
union all select 'as'
union all select 'ab'
union all select 'ac'
union all select 'ad'
union all select 'aa'create table b(b varchar(10))
insert b select 'a'
union all select 'a'
union all select 'ab'
union all select 'ac'
union all select 'ad'
union all select 'ae'
go--a表中的a列和b表的b列相同的数据
select *
from a
where exists(select 1 from b where b=a.a)--查a表中的a列和b表的b列不同的数据
select *
from a
where not exists(select 1 from b where b=a.a)
go--删除测试
drop table a,b/*--测试结果--a表中的a列和b表的b列相同的数据
a
----------
a
a
a
a
a
ab
ac
ad(所影响的行数为 8 行)
--查a表中的a列和b表的b列不同的数据
a
----------
as
aa(所影响的行数为 2 行)
--*/