admin

在Mysql中查找重复项或更多项,将其删除,但第一个输入项除外

sql

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

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

阅读 219

收藏
2021-06-07

共1个答案

admin

 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)
2021-06-07