MySQL删除旧的重复项 [英] Mysql delete older duplicates
本文介绍了MySQL删除旧的重复项的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!
问题描述
我已经有了这张数据表
id,档案ID,ean,索引,日期,(...)
id, archive id, ean, index, date, (...)
我有一些项目具有相同的存档ID,相同的ean,但索引不同.
I've got some items with same archive id, same ean, but different index.
因此,在这种情况下,我想删除较旧的(基于日期)项目,因此结果将是,每个组合archive_id/index的结果都不会超过1个.
So in this case, I want to delete older (basing on date) item, so result will be that for each combination archive_id/index there will be no more than 1 result.
推荐答案
以下(未经测试)应该可以工作:
The following (untested) should work:
DELETE FROM someTable WHERE EXISTS ( SELECT id FROM someTable AS subqTable WHERE
subqTable.id = someTable.id
AND subqTable.ean = someTable.ean
-- and other equality comparisons
AND subqTable.date AFTER someTable.date)
这篇关于MySQL删除旧的重复项的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!
查看全文