日期:2014-05-17  浏览次数:20494 次

帮我看个问题,,,在线等,,,left join问题
有A,B两个表


我selet count(1) from a 比如是10000条数据
我selet count(1) from a left join b .... 这时候为什么比10000条多呢,,,不是应该也是10000条数据吗

------解决方案--------------------
SQL code
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
*/