select * from bb.dbo.b where bb.dbo.b.id not in (select aa.dbo.a.id from aa.dbo.a)
declare @a table(id int) declare @b table(id int)insert @a select 1 union select 2 union select 3 union select 4 union select 5 insert @b select 1 union select 2 union select 4 union select 5--查询 select id from @a a where not exists(select 1 from @b where id=a.id)--结果 /*id ----------- 3(所影响的行数为 1 行) */
select * from a where a.id not in (select b.id from b)
declare @b table(id int)insert @a
select 1 union
select 2 union
select 3 union
select 4 union
select 5
insert @b
select 1 union
select 2 union
select 4 union
select 5--查询
select id from @a a
where not exists(select 1 from @b where id=a.id)--结果
/*id
-----------
3(所影响的行数为 1 行)
*/