delete user1 from t_user user1,(select t1.id from t_user t1,(select username,min(id) as minid from t_user group by username having count(username)>1) t2 where t1.username=t2.username and t1.id<>t2.minid) user2 where user1.id=user2.id
本文介绍了一种使用SQL语句来删除数据库中重复用户名的方法。通过子查询找出具有相同用户名但ID不同的记录,并仅保留每个用户名对应的最小ID记录。
delete user1 from t_user user1,(select t1.id from t_user t1,(select username,min(id) as minid from t_user group by username having count(username)>1) t2 where t1.username=t2.username and t1.id<>t2.minid) user2 where user1.id=user2.id
281
291

被折叠的 条评论
为什么被折叠?