新聞中心
這里有您想知道的互聯(lián)網(wǎng)營銷解決方案
sql查詢重復(fù)記錄、刪除重復(fù)記錄具體方法
本篇文章重點為大家講解一下sql查詢重復(fù)記錄、刪除重復(fù)記錄具體方法,有需要的小伙伴可以參考一下。

鳳岡ssl適用于網(wǎng)站、小程序/APP、API接口等需要進行數(shù)據(jù)傳輸應(yīng)用場景,ssl證書未來市場廣闊!成為創(chuàng)新互聯(lián)公司的ssl證書銷售渠道,可以享受市場價格4-6折優(yōu)惠!如果有意向歡迎電話聯(lián)系或者加微信:13518219792(備注:SSL證書合作)期待與您的合作!
查找所有重復(fù)標題的記錄:
SELECT *
FROM t_info a
WHERE ((SELECT COUNT(*)
FROM t_info
WHERE Title = a.Title) > 1)
ORDER BY Title DESC
一、查找重復(fù)記錄
1.查找全部重復(fù)記錄
Select * From 表 Where 重復(fù)字段 In (Select 重復(fù)字段 From 表 Group By 重復(fù)字段 Having Count(*)>1)
2.過濾重復(fù)記錄(只顯示一條)
Select * From HZT Where ID In (Select Max(ID) From HZT Group By Title)
注:此處顯示ID最大一條記錄
二、刪除重復(fù)記錄
1.刪除全部重復(fù)記錄(慎用)
Delete 表 Where 重復(fù)字段 In (Select 重復(fù)字段 From 表 Group By 重復(fù)字段 Having Count(*)>1)
2.保留一條記錄
Delete HZT Where ID Not In (Select Max(ID) From HZT Group By Title)
注:此處保留ID最大一條記錄
刪除多余的重復(fù)記錄
1.查找表中多余的重復(fù)記錄,重復(fù)記錄是根據(jù)單個字段(peopleId)來判斷
select * from people
where peopleId in (select peopleId from people group by peopleId having count(peopleId) > 1)
2.刪除表中多余的重復(fù)記錄,重復(fù)記錄是根據(jù)單個字段(peopleId)來判斷,只留有rowid最小的記錄
delete from people
where peopleId in (select peopleId from people group by peopleId having count(peopleId) > 1)
and rowid not in (select min(rowid) from people group by peopleId having count(peopleId )>1)
3.查找表中多余的重復(fù)記錄(多個字段)
select * from vitae a
where (a.peopleId,a.seq) in (select peopleId,seq from vitae group by peopleId,seq having count(*) > 1)
4.刪除表中多余的重復(fù)記錄(多個字段),只留有rowid最小的記錄
delete from vitae a
where (a.peopleId,a.seq) in (select peopleId,seq from vitae group by peopleId,seq having count(*) > 1)
and rowid not in (select min(rowid) from vitae group by peopleId,seq having count(*)>1)
5.查找表中多余的重復(fù)記錄(多個字段),不包含rowid最小的記錄
select * from vitae a
where (a.peopleId,a.seq) in (select peopleId,seq from vitae group by peopleId,seq having count(*) > 1)
and rowid not in (select min(rowid) from vitae group by peopleId,seq having count(*)>1)
網(wǎng)站標題:sql查詢重復(fù)記錄、刪除重復(fù)記錄具體方法
標題網(wǎng)址:http://www.dlmjj.cn/article/djieoii.html


咨詢
建站咨詢
