我在下面的SELECT查询中选择了重复的帖子,我的问题是如何将其更改为DELETE?
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';
答案 0 :(得分:0)
看看这个:
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';