A表:字段A1,A2,A3,A4
B表:字段B1,B2,B3,B4
其中A表的A1、A2构成主键
B表的B1、B2构成主键
并且A1=B1
A2=B2现在A、B两个表的数据记录条数不一致,我想查询出哪些是不一致的数据,查询语句怎么写?
用IN和EXIST可以实现吗?sql对比

解决方案 »

  1.   

    select a.*,b.* from a,b where a.A1=b.B1 and a.A2=b.B2
      

  2.   

    如果A1,A2相同的话  A3,A4相同吗
      

  3.   

    来个左链接查询看看 left join
      

  4.   

    select * from a,b 
    where a.a1=b.b1(+)
    and a.a2=b.b2(+)
    and (b1 is null or b2 is null)
      

  5.   

    select a.* 
      from a 
      full join b 
        on a.a1 = b.b1 
       and a.a2 = b.b2
     where b.b1 is null 
      

  6.   


    select a.*,b.* from a,b where a.A1=b.B1(+) and a.A2=b.B2(+)
      

  7.   

    select * from B where (B1,B2) not in (select A1,A2 from A)