我有二个表结构一样的表,都有至少200左右的数据,我要查询出二个表中不同的记录,请教下怎么快些?

解决方案 »

  1.   

    简单的话
    假设id关联,A表纪录少
    找出A表不存在,B表存在的纪录select B.* from B
    where not exists(select 'Z' from A where A.id=B.id)有个其他的方法
    select A.id,B.id from A,B
    where A.id(+)=B.id
    and A.id is null如果2表都可能缺少
    select A.*,'A' from A
    union 
    select B.*,'B' from B
    minus
    select A.*,'AB' from A,B
    where A.id=B.id没测试,仅工参考
      

  2.   

    (select * from b minus select * from a)
    union
    (select * from a minus select * from b)
      

  3.   

    上半部分是 b中有 而 a 中没有的记录
    下半部分是 a中有 而 b 中没有的记录用union 加起来 就是两个表中 全部不同的记录的集合