日期:2014-05-18 浏览次数:20701 次
if object_id('[Table1]') is not null drop table [Table1]
go
create table [Table1]([单号] int,[名称] varchar(2))
insert [Table1]
select 1,'a1' union all
select 1,'a2' union all
select 1,'a3' union all
select 2,'b1'
go
if object_id('[Table2]') is not null drop table [Table2]
go
create table [Table2]([单号] int,[名称] varchar(2))
insert [Table2]
select 1,'a1'
go
select a.*
from table1 a
left join table2 b on a.单号=b.单号 and a.名称=b.名称
where a.单号=1
and b.名称 is null
/**
单号 名称
----------- ----
1 a2
1 a3
(2 行受影响)
**/