trying to rename duplicates in MySQL database so far using that code but this only adding 1 at the end of name. So if I have
UPDATE phpfox_photo n
JOIN (SELECT title_url, MIN(photo_id) min_id FROM phpfox_photo GROUP BY title_url HAVING COUNT(*) > 1) d
ON n.title_url = d.title_url AND n.photo_id <> d.min_id
SET n.title_url = CONCAT(n.title_url, '1');
Anna
Anna
Anna
Result is
Anna
Anna1
Anna11
When I got 200 Annas result is Anna1111111111111111111111111111111111111111111....etc
how do I do it to rename in the following inc
Anna
Anna1
Anna2
Maybe you can use modulo to produce numbering, like this (SQLite example, but should be similar in mysql):
All you need is to translate
rowid
and modulo function, both availible in mysql.Then you can
CONCAT
results as you desire.With User-Defined Variables
if i didn't miss something you can make a stored procedure that iterates throw your rows using cursors to do that as following: