我想删除WordPress网站上的重复帖子 选择重复的帖子工作当前
SELECT a.ID, a.post_title, a.post_type, a.post_status
FROM wp_posts AS a
INNER JOIN (
SELECT post_title, MIN( id ) AS min_id
FROM wp_posts
WHERE post_type = 'post'
AND post_status = 'publish'
GROUP BY post_title
HAVING COUNT( * ) > 1
) AS b ON b.post_title = a.post_title
AND b.min_id <> a.id
AND a.post_type = 'post'
AND a.post_status = 'publish'
和
this query that i need has error
DELETE a.*
FROM wp_posts AS a
INNER JOIN (
SELECT post_title, MIN( id ) AS min_id
FROM wp_posts
WHERE post_type = 'post'
AND post_status = 'publish'
GROUP BY post_title
HAVING COUNT( * ) > 1
) AS b ON b.post_title = a.post_title
AND b.min_id <> a.id
AND a.post_type = 'post'
AND a.post_status = 'publish'
这是错误消息:
意外的令牌(靠近a)意外的令牌(附近)。意外的令牌 (近*)
答案 0 :(得分:1)
第一个SELECT
帖子ID。然后使用带有DELETE
子句的WHERE IN
语句。
注意:在执行整个查询之前,请测试IN()
子句中的子查询是否返回正确的ID。
DELETE FROM wp_posts
WHERE ID IN (
SELECT a.ID
FROM wp_posts AS a
INNER JOIN (
SELECT post_title, MIN( id ) AS min_id
FROM wp_posts
WHERE post_type = 'post'
AND post_status = 'publish'
GROUP BY post_title
HAVING COUNT( * ) > 1
) AS b ON b.post_title = a.post_title
AND b.min_id <> a.id
AND a.post_type = 'post'
AND a.post_status = 'publish'
)