有一个表  有500万条数据需要删除重复,重复的都是10位以内的数字。 都是int类型的使用如以下类似语句,实在太慢,执行了几个小时都没有弄完。
delete t1 from a t1,a t2 where t1.tid=t2.tid and t1.ID>t2.ID;ID    tid
1    3241
2    3241
3    545554
4    545554
5    545455需要将tid 中 ,重复的删除。

解决方案 »

  1.   

    create table newtt as
    select t1.* from a t1,a t2 where t1.tid=t2.tid and t1.ID>t2.ID;
      

  2.   

    是这样吗CREATE TABLE t2 SELECT MIN(ID) AS id,tid FROM a GROUP BY tid ;
      

  3.   

    500万数据,靠一个SQL语句会很慢,这个已经在论坛中讨论过了。 建议使用存储过程或者程序来实现。 
      

  4.   

     
    ACMAIN_CHM   大侠 ,给个方法吧。。
      

  5.   

    先把重复的id得到
    select id from table group by id having count(*) > 1
    然后再组织sql去删除,这样可以避免了大表的自连接问题。
      

  6.   

    在tid上加索引即可,id应该是自增逐渐
      

  7.   

    然后再组织sql去删除,这样可以避免了大表的自连接问题。这个怎么组织?DELETE FROM   t2  WHERE tid IN (SELECT tid FROM t1)这样吗?
      

  8.   

    create table tt_new like ttinstert into tt (tid) (select tid from tt group by tid)rename table tt to tt_bak;
    rename table tt_new to tt;