delete from table1 a
where (a.q1, a.q2) IN(select q1,q2 from table1 group by q1,q2 having count(*) > 1)
and q3 not in (select min(q3) from table1  group by q1,q2 having count(*)>1)
参考网上的,用于删除字段q1,q2组合重复的记录。
但是一直提示语法错误。
求高人释疑。

解决方案 »

  1.   

    Mysql版本
    Ver 8.42 Distrib 5.5.9, for Linux on x86_64
      

  2.   


    delete a from table1 a,(select q1,q2 from table1 group by q1,q2 having count(*) > 1) b,
    (select min(q3) mq from table1 group by q1,q2 having count(*)>1) c
    where a.q1=b.q1 and a.q2=b.q2 and a.q3=c.mq;
      

  3.   

    给个另类解决思路:
    删除多,可以作废了表。重新建一个新表,把有用数据insert 到新表中。这样可能会比你删除要快,但要注意操作的磁盘空间。很容易撑爆。
      

  4.   

    delete a from table1 a left join (select q1,q2,min(q3) as q3 from table1 group by q1,q2) b using(q1,q2,q3)
    where b.q1 is null;
      

  5.   

    谢谢各位的支持,已经解决了。用了比较笨的方法。
    create table t_tmp
    select * from t
    group by c1,c2;
    drop table t;
    alter table t_tmp rename to t;
    然后重新建立索引。
    速度也在接受范围内。