删除mysql上的重复记录?
我有这个 mysql 查询,可以查找重复项以及每个主题的出现次数:
SELECT name,
COUNT(name) AS NumOccurrences
FROM topics
GROUP BY name
HAVING ( COUNT(name) > 1 )
但我想要做的是删除找到的所有重复项。我只想要每个主题有一个唯一的名称,并且不能重复!谢谢
I have this mysql query that finds duplicates and the number of occurances for each topic:
SELECT name,
COUNT(name) AS NumOccurrences
FROM topics
GROUP BY name
HAVING ( COUNT(name) > 1 )
but what I want to do is delete all the duplicates that are found. I only want one unique name for each topic, and no duplicates!! thanks
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(2)
我会将所有唯一条目复制到一个新表中:
检查数据,然后在确定一切正常时删除旧表,并将新表重命名为旧表。
然后使名称列唯一,这样您就不必再次执行此操作。
干杯
I would copy all the unique entries to a new table:
Check the data, then delete your old table when you're sure everything's good and rename the new table to the old one.
Then make the name column unique so you won't have to do this again.
Cheers