I have a table like this
CREATE TABLE IF NOT EXISTS users_groups(
id INT(11) UNSIGNED NOT NULL AUTO_INCREMENT,
user_id INT(11) UNSIGNED NOT NULL,
name VARCHAR(250) NOT NULL,
is_deleted BOOLEAN NOT NULL DEFAULT false,
creation_date DATETIME NOT NULL,
last_modification_date DATETIME NOT NULL,
PRIMARY KEY (id)
);
And I would like to turn the columns (user_id, name) as unique, but the problem I have is that I already have duplicates in that columns. In some cases the columns are repeated many times.
I would like to write a query to update the duplicates rows concatenating some value in the name, for example concatening '*' for the first duplicate '**' for the second duplicate, and so on.
Is this possible writing a query?
I can get the group that I want to modify, but I am not sure if it is possible to achieve what I want with mysql
select users_groups.id, users_groups.user_id, users_groups.name
from users_groups
inner join (select user_id, name, count(*) from users_groups group by user_id, name having count(*) > 1) as u on u.user_id = users_groups.user_id
where users_groups.name = u.name;