如何从mysql数据库中删除重复的条目? [英] How to remove duplicate entries from a mysql db?
问题描述
如何删除所有重复,除了一个,所以我可以在标题列之后添加一个UNIQUE键?
此命令添加了一个唯一的键,并删除生成错误的所有行(由于唯一的键)。这将删除重复项。
ALTER IGNORE TABLE表ADD UNIQUE KEY idx1(title);
编辑:请注意,此命令可能不适用于InnoDB表。有关解决方法,请参阅此帖。 (感谢匿名用户的信息。)
I have a table with some ids + titles. I want to make the title column unique, but it has over 600k records already, some of which are duplicates (sometimes several dozen times over).
How do I remove all duplicates, except one, so I can add a UNIQUE key to the title column after?
This command adds a unique key, and drops all rows that generate errors (due to the unique key). This removes duplicates.
ALTER IGNORE TABLE table ADD UNIQUE KEY idx1(title);
Edit: Note that this command may not work for InnoDB tables for some versions of MySQL. See this post for a workaround. (Thanks to "an anonymous user" for this information.)
这篇关于如何从mysql数据库中删除重复的条目?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!