SQL重复记录查询的几种方法

时间:2021-08-17 06:23:53
1 查找表中多余的重复记录,重复记录是根据单个字段
1
select * from TB_MAT_BasicData1 2 where MATNR in ( select MATNR from TB_MAT_BasicData1 group by MATNR having count(MATNR)>1)

2.表需要删除重复的记录(重复记录保留1条),

select distinct * into #Tmp from TB_MAT_BasicData1
drop table TB_MAT_BasicData1
select * into TB_MAT_BasicData1 from #Tmp
drop table #Tmp

 

3.查询重复
select count(1),UnitsofmeasureGuid from TB_MAT_UnitsOfMeasure
group by UnitsofmeasureGuid
having count(1)>1