我有很多文章是重复的,这意味着一篇文章被写了不止一次。我想找到那些使用这个 MySQL 命令的人:
select post_title,post_content,count(*) as count from wp_posts
group by post_content
having count(*)>1
ORDER BY count(*) DESC
但是,我怎样才能只删除重复的帖子,这样如果任何帖子的副本超过 1 个,则只剩下 1 个副本。
任何方法将不胜感激。
我有很多文章是重复的,这意味着一篇文章被写了不止一次。我想找到那些使用这个 MySQL 命令的人:
select post_title,post_content,count(*) as count from wp_posts
group by post_content
having count(*)>1
ORDER BY count(*) DESC
但是,我怎样才能只删除重复的帖子,这样如果任何帖子的副本超过 1 个,则只剩下 1 个副本。
任何方法将不胜感激。
我建议在尝试以下操作之前备份您的 SQL 数据库。
尝试:
DELETE bad_rows . * FROM ktz3_posts AS bad_rows INNER JOIN (
SELECT post_title, MIN( id ) AS min_id
FROM ktz3_posts
GROUP BY post_title
HAVING COUNT( * ) >1
) AS good_rows ON good_rows.post_title = bad_rows.post_title
AND good_rows.min_id <> bad_rows.id
由于上述代码未经测试,您可以尝试Duplicate Post Remover。