二张表结构一样的表,表1、表2唯一索引字段是:字段a+字段b+字段c现在想查表二张表的不同记录,也就是表1中有多少记录在表2中没有的

解决方案 »

  1.   

    select count(*) as 记录数
    from 表1 a left join 表2 b
    on a.字段a=b.字段a and a.字段b=b.字段b and a.字段c=b.字段c and b.字段 is null
      

  2.   

    select a.* from 表1 a left join 表2 b
    on a.字段a=b.字段a and a.字段b=b.字段b and a.字段c=b.字段c
    where b.字段a is null
      

  3.   

    1楼:
    b.字段 is null 写在on里面错的
      

  4.   

    --假设表一和表二有三个字段 a,b,c--在表一中有的再表二中没有的
    select *
    from b1
    where 
    not exists(select * from b2 where b1.a=b2.a and b1.b=b2.b and b1.c=b2.c)
    --在表二中有的再表一中没有的
    select * from b2
    where 
    not exists(select * from b1 where b1.a=b2.a and b1.b=b2.b and b1.c=b2.c)