急求!!!请问,如何比较两个表中的数据,一条条查。如果数据相同,查一条删一条;如果数据不同,分别保留。最后将两个表中保留的不一样的数据 输出来并共同导入到另外一个专门盛放错误的表中。PHP

解决方案 »

  1.   

    呵呵,最简单的做法就是查询一个表所有数据循环跟另一个表的比较还有一个就是直接联表查询,
    比如select a,id,b.id from a,b where a.filed1=b.filed1 and a.filed2=b.filed2 and a.filed3=b.filed3这样查询然后删除了
      

  2.   

    1、取得 表A 的记录数备用 select count(*) as cnt from A
    2、提取出与表A不同的表B的记录 select * from A union select * from B limit cnt
    3、取得 表B 的记录数备用 select count(*) as cnt from B
    4、提取出与表B不同的表A的记录 select * from B union select * from A limit cnt后面怎么做?你自己决定
      

  3.   

    不要那么麻烦了,把表发出来,
    create table ..
    insert into ..然后把你想要的结果做一份范本出来
      

  4.   

    select a,id,b.id from a,b where a.filed1=b.filed1 and a.filed2=b.filed2 and a.filed3=b.filed3
    然后再删除吧
      

  5.   

    亲们,谢谢大家支持,在大家的帮助下已解决delete a,b FROM a LEFT JOIN b ON a.c_num=b.c_num and a.c_jifen=b.c_jifen where a.c_num=b
    .c_num