SQL 删除重复记录,只保留一条记录

删除表中多余的重复记录,重复记录是根据单个字段(id)来判断,只留有rowid最小的记录 

//删除用户 根据用户名,并且不包括最小ID
delete from users where username in (
         --根据用户名称排序,大于1
	select username from users group by username having count(username) > 1
 
 ) and Id not in (
        --根据用户名排序,获取最小ID
	select min(Id) from users group by username having count(username) > 1
);

转载请注明出处 AE博客|墨渊 » SQL 删除重复记录,只保留一条记录

相关推荐

发表评论

路人甲

网友评论(0)