I have done a little bit of searching and came to WHERE EXISTS condition:
UPDATE wp_posts SET post_name = ''
WHERE EXISTS
(SELECT dup.post_name FROM wp_posts AS dup
GROUP BY dup.post_name HAVING count(id) > 1
WHERE dup.post_name = wp_posts.post_name)
Heres another version, but it gives me error: #1093 - You can’t specify target table ‘wp_posts’ for update in FROM clause
UPDATE wp_posts
SET post_name = ''
WHERE id IN(SELECT id FROM wp_posts
INNER JOIN (SELECT post_name FROM wp_posts
GROUP BY post_name HAVING count(id) > 1) dup ON wp_posts.post_name = dup.post_name)
This code will return all ids of duplicate post-name rows:
SELECT id FROM wp_posts
INNER JOIN (SELECT post_name FROM wp_posts
GROUP BY post_name HAVING count(id) > 1) dup ON wp_posts.post_name = dup.post_name
well, see, the thing is… you can’t specify target table ‘wp_posts’ for update in FROM clause
run your dupes into a temp table
this is an acceptable strategy whenever dealing with dupes, because after you fix your data, you’re going to do something so that the dupes never happen again, right?