delete from
tabname a where a.id!=(select min(id) from tabname b where a.sn=b.sn);

解决方案 »

  1.   

    create tabel temp (和你以前的格式一样)
    insert into temp select id,sn,……from origintable group by sn;
    delete from origintable;
    insert into origintable select id,sn…… from temp;
    drop table temp
      

  2.   

    okdw, 我执行了前两句:
    create tabel temp (和你以前的格式一样)
    insert into temp select id,sn,……from origintable group by sn;现在表temp 里是干净的数据, origintable 是原来带重复记录的数据, 我想找到那些数据是origintable 里有而temp里没有的, 该怎么写?
      

  3.   

    insert into temp select id,sn,……from origintable group by sn order by id desc
    delete from origintable where id not in (select id from temp)
    估计的写法不过,为什么不在php脚本里处理这样的逻辑删除操作,一定要用纯粹的sql脚本处理?
      

  4.   

    我想执行
    SELECT id FROM origintable WHERE id NOT IN (SELECT id FROM temp)
    选出origintable 里有 temp里没有的记录, 但是mysql报错.
    babystudio, 用php怎么写? 我用php写就带上了循环, 总是超时
      

  5.   

    Mysql现只有 4.1.0的版本支持子查询,不过还在测试,劝你还是用PHP干吧。