日期:2014-05-17 浏览次数:20547 次
create table #a(
id int identity(1,1) primary key,
enName varchar(30)
)
insert into #a
select 'abcde fighi' union
select 'zzzzz ddd' union
select 'xxxxx yyyyyyy'
create table #b
(
enName varchar(30),
cnName varchar(30),
grop varchar(10)
)
insert #b
select 'abcde fighi','用户一','g1' union
select 'abcde fighi','用户一','g2' union
select 'zzzzz ddd','用户二','g1'
select distinct a.id,b.cnName as Name
from #a a
join #b b on a.enName=b.enName
union
select id,enName as Name
from #a
where enName not in(select enName from #b)
order by id
id Name
----------- ------------------------------
1 用户一
2 xxxxx yyyyyyy
3 用户二
(3 行受影响)