Sql Server 查询多条重复数据 删除并保留一条

总是不会查重和删除多余数据

delete sysdba.PRODUCT from sysdba.PRODUCT  a
where  exists  (select  Name,ACTUALID from sysdba.PRODUCT b where a.name=b.name and a.ACTUALID = b.ACTUALID group by  Name,ACTUALID having count(*) > 1)
and PRODUCTID not in (select min(PRODUCTID) from sysdba.PRODUCT group by  Name,ACTUALID having count(*)>1)


select * from   sysdba.PRODUCT  a
where  exists  (select  Name,ACTUALID from sysdba.PRODUCT b where a.name=b.name and a.ACTUALID = b.ACTUALID group by  Name,ACTUALID having count(*) > 1)
and PRODUCTID not in (select min(PRODUCTID) from sysdba.PRODUCT group by  Name,ACTUALID having count(*)>1) 


你可能感兴趣的:(Sql Server 查询多条重复数据 删除并保留一条)