27,579
社区成员
发帖
与我相关
我的任务
分享
select * from table2 where iid not in(select id from table1)
declare @table1 table (id int,title varchar(1),txt varchar(1))
insert into @table1
select 1,'a','d' union all
select 2,'b','e' union all
select 3,'c','f'
declare @table2 table (id int,iid int)
insert into @table2
select 1,2 union all
select 2,3 union all
select 3,4
select b.* from @table2 b
left join @table1 a
on b.iid=a.id
where a.id is null
/*
id iid
----------- -----------
3 4
*/
select * from table2 a
left join table1 b on a.iid=b.id
where b.id is null
select * from table2 t2 where not exists (select 1 from table1 where id=t2.iid)