MSSQL 删除重复并只保留一条
Posted Alex_Mercer
tags:
篇首语:本文由小常识网(cha138.com)小编为大家整理,主要介绍了MSSQL 删除重复并只保留一条相关的知识,希望对你有一定的参考价值。
重复值查找
select field1,field2 from table
group by field1,field2 having COUNT(*)>1
删除重复值,只保留ID最小的那条
delete table
where field1 in (select field1 from VersionProductRelation a
group by field1,field2 having COUNT(*)>1)
and field2 in (select field2 from VersionProductRelation a
group by field1,field2 having COUNT(*)>1)
and ID not in (
select MIN(ID) from table
group by field1,field2 having COUNT(*)>1)
以上是关于MSSQL 删除重复并只保留一条的主要内容,如果未能解决你的问题,请参考以下文章