sql查找重复数据

1.查找重复数据表的id以及重复数据的条数

 

select max(id) as nid,count(id) as 重复条数 from tableName

group by linkname Having Count(*) > 1

 

2.查找重复数据表的主键

 

 

select id from UsedCar_Articles

 

where id not in (

 

select min(id) as nid from UsedCar_Articles

 

group by ArticleTitle  Having Count(id) > 1

 

)

 

3.删除重复的数据

 

delete from UsedCar_Articles

 

where id not in (

 

select min(id) as nid from UsedCar_Articles

 

group by ArticleTitle  Having Count(id) > 1

 

)

4.插入重复的数据

INSERT Articles (ClassID, ArticleTitle,ArticleInfo,

ArticleClicks,IsHot,IsTop,IssueTime,

SiteProvinceID,SiteCityID)

SELECT ClassID, ArticleTitle,ArticleInfo,

ArticleClicks,IsHot,IsTop,IssueTime,

SiteProvinceID,SiteCityID

FROM Articles

 

 

你可能感兴趣的:(sql)