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

解决方案 »

  1.   

    你这是两表的连接啊
    如果符合条件的b的字段对应的a中字段有多个的时候就会有多条记录
    超过10000条很正常啊比如
    a.id=1
    在b中id=1的有多条就会产生更多记录了
      

  2.   


    如果说是A表和B表的关联条件是一一对应,那么返回的行数应该是A表的行数,但是A表和B表的关联条件是1对多的关系,那么就不是了,就会多于A表的数据量问题就应该在这里
      

  3.   

    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
    */
      

  4.   

    create table test1( 
           id int,              
           name varchar(10) 

    INSERT INTO test1 VALUES (1,'a')
    INSERT INTO test1 VALUES (2,'b')
    INSERT INTO test1 VALUES (3,'c')
    INSERT INTO test1 VALUES (4,'d')
    INSERT INTO test1 VALUES (5,'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----------------------------------------------------
    --test2有重复的也会同样的效果,结果集也是6条记录
    /*
    id     name     id      name
    1 a 1 q
    2 b 2 w
    2 b 2 r
    3 c NULL NULL
    4 d NULL NULL
    5 e NULL NULL
    */
      

  5.   

    create table test1( 
           id int,              
           name varchar(10) 

    INSERT INTO test1 VALUES (1,'a')
    INSERT INTO test1 VALUES (2,'b')
    INSERT INTO test1 VALUES (3,'c')
    INSERT INTO test1 VALUES (4,'d')
    INSERT INTO test1 VALUES (5,'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----------------------------------------------------
    --test2有重复的也会同样的效果,结果集也是6条记录
    /*
    id     name     id      name
    1 a 1 q
    2 b 2 w
    2 b 2 r
    3 c NULL NULL
    4 d NULL NULL
    5 e NULL NULL
    */
      

  6.   


    B表有重复的当然也会匹配对应的NULL,你自己测试下
      

  7.   

    你的左连接的 ON后面的条件没写清楚造成的。a.主键=b.主键 尝试下看看