假设两表以aa字段关联:select m.aa,m.bb into p
from m left join n on a.aa=b.aa
where n.aa is null

解决方案 »

  1.   

    将m表和n表同时写入p表
    然后删除m和n中同时存在的纪录
      

  2.   

    insert into P(aa,bb) select aa,bb from M where aa not in(select aa from N) and bb not in(select bb from N)
      

  3.   

    用了 "not in" 可能速度会有点慢
      

  4.   

    “然后删除m和n中同时存在的纪录”
    这句怎么写啊,ps:最好还是一句话 比较好~
      

  5.   

    中海的这个好
    select M.aa,M.bb 
    from M left join N on M.aa=N.aa
    where N.id is null
      

  6.   

    insert into P(aa,bb) select M.aa,M.bb from M left join N on M.aa=N.aa where N.id is null删除的:
    不知道楼主是要删除哪个表的,下面是删除M表中的
    delete from M where aa in(select M.aa from M inner join N on M.aa=N.aa and M.bb=N.bb)
      

  7.   

    insert p (select m.aa,m.bb from m where m.aa+m.bb not in (select n.aa+n.bb from n))
      

  8.   

    victorycyz(中海)这个 bb怎么没考虑啊,比如  M 表                 n表             P表
    aa  bb               aa  bb            aa  bb  
    -------------------------------------------------
    1   4                1   7              1   4    
    1   6                6   3              1   6  
    1   7                7   8
                         11  W
                         2   3
      

  9.   

    insert p (select m.aa,m.bb from m where m.aa+m.bb not in (select n.aa+n.bb from n))
    这个有点投机取巧了吧,呵呵,如果  11+34   他等于 1+134么?
      

  10.   

    insert into P(aa,bb) select aa,bb from M where aa not in(select aa from N) and bb not in(select bb from N)
     晕,这个也什么记录也没有哦,
      

  11.   

    insert into P(aa,bb) select aa,bb from M where aa not in(select aa from N) or bb not in(select bb from N)这个就可以了,不过我去学学 join了,