I created slug field for a table and they need to be unique but some of them aren't so i think i can add random characters at the end of them to make them unique.
So this is my SELECT query:
SELECT slug,count(*) as num FROM table GROUP BY slug HAVING num > 1
This is the UPDATE query:
UPDATE table SET slug = CONCAT(slug,'-',SUBSTRING(MD5(NOW()),1,2))
I couldn't manage to combine this 2 queries.
You can use a
JOIN
:However the problem with the above is that it does not generate unique string values.
Demo here
One way to get around this, is to use row numbers calculated by variables:
Demo here