日期:2014-05-17 浏览次数:20620 次
id 001 002 003 004 005 006
002 003 005
003 004 005
select * from A where not exists ( select * from B where A.id = id ) and not exists ( select * from C where A.id = id )
------解决方案--------------------
--1 select * from a where not exists(select 1 from b where b.id=a.id) and not exists(select 1 from c where c.id=a.id)
------解决方案--------------------
SELECT * FROM A WHERE NOT EXISTS ( SELECT 1 FROM ( SELECT * FROM B UNION SELECT * FROM C) AS D WHERE A.id = D.id )
------解决方案--------------------
declare @t1 table (id int)
insert into @t1
select 1 union all
select 2 union all
select 3 union all
select 4 union all
select 5 union all
select 6
--> 测试数据: @t2
declare @t2 table (id int)
insert into @t2
select 1
--> 测试数据: @t3
declare @t3 table (id int)
insert into @t3
select 3
select * from @t1
except
(select * from @t2
union
select * from @t3)