34,590
社区成员
发帖
与我相关
我的任务
分享
--try
declare @a table (name nvarchar(10))
insert into @a select 'AAA'
UNION ALL SELECT 'BBB'
UNION ALL SELECT 'CCC'
UNION ALL SELECT 'DDD'
DECLARE @B TABLE (NAME NVARCHAR(10))
declare @c table (name nvarchar(10))
INSERT INTO @B SELECT 'AAA'
UNION ALL SELECT 'BBB'
UNION ALL SELECT 'EEE'
UNION ALL SELECT 'FFF'
insert into @C
select * from @a a where
not exists (select 1 from @b where a.name=name)
union all
select * from @b a where
not exists (select 1 from @a where a.name=name)
select * from @c
-->建立表A
if object_id('A') is not null drop table A
create table A(name nvarchar(4))
insert into A
select 'AAA'union all
select 'BBB' union all
select 'CCC' union all
select 'DDD'
-->建立表B
if object_id('B') is not null drop table B
create table B(name varchar(4))
insert into B
select 'AAA'union all
select 'BBB' union all
select 'EEE' union all
select 'FFF'
-->测试
select * from A where A.name not in (select * from B )
union
select * from B where B.name not in (select * from A)
select *
from a
where not exists(select 1 from b where b.name=a.name)
union
select *
from b
where not exists(select 1 from a where a.name=b.name)