MySQL如何删除重复数据?

理由
举报 取消

例如如下数据id name age1 abc 202 bcd 213 abc 224 cde 195 abc 18删除name字段重复的数据,只留下一个,删减后的结果如下id name age1 abc 202 bcd 214 cde 19请问有没有什么办法能够实现,之前网上找的对于小数据库还行,大一些的数据库(GB级别以上的),就没法处理了

2017年9月20日 2 条回复 1072 次浏览

发起人:Traphix 初入职场

回复 ( 2 )

  1. 浪琴
    理由
    举报 取消

    实在太容易了。

    建一个新表,字段与老表相同。

    然后建唯一索引。

    编写程序,或利用存储过程,逐条往新表插入,最后的新表即想要的结果。

  2. 爱天涯
    理由
    举报 取消

    delete from dede_taglist where tag in (select tag from dede_taglist group by tag having count(tag) > 1) and tid not in (select min(tid) from dede_taglist group by tag having count(tag)>1);

    帮我看看,哪里错误了 谢谢

我来回答

Captcha 点击图片更换验证码