日期:2014-05-17 浏览次数:20625 次
create table test1( 
       id int,              
       name varchar(10) 
) 
INSERT INTO test1 VALUES (1,'a')
INSERT INTO test1 VALUES (1,'b')
INSERT INTO test1 VALUES (2,'c')
INSERT INTO test1 VALUES (3,'d')
INSERT INTO test1 VALUES (4,'e')
create table test2( 
       id int,              
       name varchar(10) 
) 
INSERT INTO test2 VALUES (1,'q')
INSERT INTO test2 VALUES (2,'w')
INSERT INTO test2 VALUES (2,'r')
select * from  test1 a left join test2 b on a.id=b.id
----------------------------------------------------
--注意结果集有6条数据,test1只有5条
/*
id     name    id       name
1    a    1    q
1    b    1    q
2    c    2    w
2    c    2    r
3    d    NULL    NULL
4    e    NULL    NULL
*/