sql语句操作数据库重复数据
1.示例表
- Create Table TableA
- (
- id int,
- NameA varchar(10)
- )
2.判断NameA列是否有重复数据
- select NameA from TableA group by NameA having count(1)>1
3.删除NameA列重复的数据,只留一条。
- alter table TableA add autoID int identity
- delete TableA where autoID not in (select min(autoID) as autoID from TableA group by NameA)
- alter table TableA drop column autoID
先增加一个自增列,然后删除不是最小的,删除自增列