sql 删除重复语句只保留一条

1.查询重复记录

select * from 表名
where 重复字段 in (select  重复字段 from  表名  group  by  重复字段 having  count(重复字段) > 1)

 

2.删除保留一条重复记录

delete from 表名
where 重复字段  in (select  重复字段 from 表名 group  by  重复字段   having  count(重复字段) > 1)
and ID not in (select min(ID) from  表名  group by 重复字段 having count(重复字段 )>1)

posted @ 2016-09-18 16:20  隨興∥隨心  阅读(114)  评论(0编辑  收藏  举报