MYSQL查詢重復(fù)記錄的方法
作者:佚名
重復(fù)記錄是我們使用MYSQL數(shù)據(jù)庫經(jīng)常會遇到的問題,下文就為您介紹幾種查詢重復(fù)記錄的方法,供您參考學(xué)習(xí)之用。
MYSQL查詢重復(fù)記錄的方法很多,下面就為您介紹幾種最常用的MYSQL查詢重復(fù)記錄的方法,希望對您學(xué)習(xí)MYSQL查詢重復(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)
【編輯推薦】
責(zé)任編輯:段燃
來源:
互聯(lián)網(wǎng)