select * from TB1 where not exsits (select * from TB2)
select * from tb1 where not exsits (select * from tb2)
select * from tb1 where not exists (select * from tb2)
可能描述错了,这两个表应该是这样的 如下: tb1 guid col col1 dadf abc 111 1erw cde 111 21qe qaz 222 qweq tgb 222tb2 guid col2 col3 w5wr abc 111 w34f qaz 222
declare @t1 table (col varchar(5), col1 int) insert into @t1 select 'abc', 111 union all select 'cde', 111 union all select 'qaz', 222 union all select 'tgb', 222 declare @t2 table (col2 varchar(5), col3 int) insert into @t2 select 'cde', 111 union all select 'qaz', 222 select * from @t1 where not exists(select * from @t2 where col=col2 and col1=col3) col col1 ----- ----------- abc 111 tgb 222(2 行受影响)
select * from tb1 where not exists (select * from tb2 where tb1.col=tb2.col2 and tb1.col1=tb2.col3)
如下:
tb1
guid col col1
dadf abc 111
1erw cde 111
21qe qaz 222
qweq tgb 222tb2
guid col2 col3
w5wr abc 111
w34f qaz 222
declare @t1 table (col varchar(5), col1 int)
insert into @t1 select
'abc', 111 union all select
'cde', 111 union all select
'qaz', 222 union all select
'tgb', 222 declare @t2 table (col2 varchar(5), col3 int)
insert into @t2 select
'cde', 111 union all select
'qaz', 222
select * from @t1
where not exists(select * from @t2 where col=col2 and col1=col3)
col col1
----- -----------
abc 111
tgb 222(2 行受影响)