操作前先备份数据库,一定要先备份!!!

mysql去重复语句,只保留一条代码如下,这里是保留ID最小的一条,也就是最先发布的一条:

DELETE FROM archives WHERE title IN (SELECT title FROM (SELECT title FROM archives GROUP BY title HAVING COUNT(title)>1) e)
 AND id NOT IN (SELECT Id FROM (SELECT MIN(id) AS Id FROM archives GROUP BY title HAVING COUNT(title)>1) t)
下面是保留最新发布的一条。

DELETE FROM archives WHERE title IN (SELECT title FROM (SELECT title FROM archives GROUP BY title HAVING COUNT(title)>1) e)
 AND id NOT IN (SELECT Id FROM (SELECT MAX(id) AS Id FROM archives GROUP BY title HAVING COUNT(title)>1) t)

点赞(1)

Comment list 共有 0 条评论

暂无评论
立即
投稿
发表
评论
返回
顶部
{__SCRIPT__}