日期:2014-05-17 浏览次数:20484 次
select a.name,a.data_,b.data_ as data_2
from 表一 a
left join 表二 b on a.name=b.name
create table 表一(name varchar(10),data_ int)
insert into 表一
select 'A',4 union all
select 'b',6 union all
select 'A',2 union all
select 'B',3 union all
select 'C',4 union all
select 'D',5
create table 表二(name varchar(10),data_ int)
insert into 表二
select 'A',3 union all
select 'b',5 union all
select 'B',2 union all
select 'D',1
select a.name,a.data_,b.data_ 'data_2'
from 表一 a
left join 表二 b on a.name=b.name collate Chinese_PRC_CS_AS
/*
name data_ data_2
---------- ----------- -----------
A 4 3
b 6 5
A 2 3
B 3 2
C 4 NULL
D 5 1
(6 row(s) affected)
*/
if object_id ('T1') is not null
drop table T1
create table T1(name varchar(20),data_ int)
insert into T1
select 'A',4 union all
select 'b',6 union all
select 'A',2 union all
select 'B',3 union all
select 'C',4 union all