2

我有一个表,其中包含 id、长度、时间等行,其中一些是重复的,其中某些行的长度和时间是相同的。我想删除提交的第一行的所有副本。

id | length | time
01 | 255232 | 1242
02 | 255232 | 1242 <- Delete that one

我有这个来显示表中的所有重复项。

SELECT idgarmin_track, length  , time
FROM `80dage_garmin_track`
WHERE length in
       ( SELECT length
         FROM `80dage_garmin_track`
         GROUP
         BY length
         HAVING count(*) > 1 )
ORDER BY idgarmin_track, length, time LIMIT 0,500
4

3 回答 3

4
 DELETE FROM `80dage_garmin_track` t1
 WHERE EXISTS (SELECT 1 from `80dage_garmin_track` t2
          WHERE t1.Length = t2.Length
           AND t1.Time = t2.Time
           AND t1.idgarmin_track > t2.idgarmin_track)
于 2010-10-13T07:19:49.043 回答
0

If you can take your table offline for a period, then the simplest way is to build a new table containing the data you want and then drop the original table:

create table `80dage_garmin_track_un` like `80dage_garmin_track`;

insert into `80dage_garmin_track_un`
select min(idgarmin_track), length, time 
group by length, time;

rename table `80dage_garmin_track` to old, `80dage_garmin_track_un` to `80dage_garmin_track`;

drop table old;
于 2010-10-13T07:21:26.260 回答
0

我有同样的问题Holsteinkaa,我只是这样使用它:

 delete from table where id in ( select * from (
    SELECT id FROM table t1
    WHERE EXISTS (SELECT 1 from table t2
      WHERE t1.field = t2.field
       AND t1.id > t2.id
    ) 
 ) as tmp )

我试图将其作为对 Michael Pakhantsov 答案的评论,但我不能:/抱歉

于 2013-01-05T14:19:43.167 回答