34,593
社区成员
发帖
与我相关
我的任务
分享
--SQL 2000
select * from b where id not in (select id from a)
--or
select * from b where not exists (select 1 from a where a.id=b.id) --id是唯一列;
--SQL 2005,若表结构相同,则:
select * from b
except
select * from a
Select * from b Where not exist (select * from a)
--或
Select * from b Where id not in (select id from a)
if object_id('num')is not null drop table num
go
create table num( n int )
insert into num
select 1 union
select 2 union
select 3 union
select 4 union
select 5 union
select 6 union
select 7 union
select 8 union
select 9
if object_id('num1')is not null drop table num1
go
create table num1( n int )
insert into num1
select 1 union
select 2 union
select 7 union
select 8 union
select 9
select * from num
except
select * from num1
n
-----------
3
4
5
6
(4 行受影响)
select * from b where not exists (select * from a where id=b.id)
select * from b where not exist (select * from a where id=b.id)
SELECT * FROM B WHERE ID NOT IN (SELECT ID FROM A )
ID唯一
SELECT * FROM B WHERE NOT EIXSTS(SELECT 1 FROM A WHERE 关联字段)
2005用EXCEPT