update dff_posts join (set @count := 0, @prev := ''; select tmp.id, tmp.name from ( select dff_posts.id, IF(@prev <> dff_posts.post_name, @count := 1, @count := @count + 1), @prev := dff_posts.post_name, CONCAT(dff_posts.post_name, '-', @count) name from dff_posts, (SELECT `post_name`, COUNT(*) AS `count` FROM `dff_posts` GROUP BY `post_name` HAVING `count` > 1) tmp2 where dff_posts.post_name = tmp2.post_name order by dff_posts.post_name ) tmp) jtmp on jtmp.id = dff_posts.id set dff_posts.post_name = jtmp.name; |