您的位置:首页 > 数据库

Sql 删除重复行记录

2008-03-03 09:58 162 查看
首先查询具有重复记录的所有记录

select iCityID,name,count(*) as count from testUpdate group by iCityID,name
having count(*)>1
order by count desc

(1) 通过以下语句可以删除掉重复的记录

delete from testUpdate where exists(
select 1 from testUpdate t
where testUpdate.userid>t.userId and testUpdate.name=t.name and testUpdate.iCityID=t.iCityID)

(2)也可以通过这种方式删除重复记录
delete from TestUpdate where userID not in (select max(userid) from TestUpdate group by iCityID,name)

删除记录要小心操作,最好做个备份。
内容来自用户分享和网络整理,不保证内容的准确性,如有侵权内容,可联系管理员处理 点击这里给我发消息
标签: