我试图更新表中重复的用户名记录。这是我提出的更新,但这更新了所有重复的记录。我怎么能更新一个呢?
update xxx_users set username = CONCAT(username,"dup") where exists(
SELECT username, COUNT(username) FROM xxx_users GROUP BY username HAVING COUNT(username) > 1);
我很感激能提供的任何帮助。谢谢!假设您的xxx_users表有一个基于自增id的主键,您可以尝试:
update xxx_users u
inner join (
select min(id) id
from xxx_users
group by username
having count(*)>1
) t ON t.id = u.id
set username = CONCAT(username,"dup")