新聞中心
此文章主要向大家介紹的是SQL Server查找與刪除重復(fù)記錄的實際操作方法,你是否對如何正確查出字段dd中有重復(fù)的記錄的實際操作有不解之處?即要知道哪些記錄是重復(fù)的,怎么弄?

創(chuàng)新互聯(lián)-專業(yè)網(wǎng)站定制、快速模板網(wǎng)站建設(shè)、高性價比天鎮(zhèn)網(wǎng)站開發(fā)、企業(yè)建站全套包干低至880元,成熟完善的模板庫,直接使用。一站式天鎮(zhèn)網(wǎng)站制作公司更省心,省錢,快速模板網(wǎng)站建設(shè)找我們,業(yè)務(wù)覆蓋天鎮(zhèn)地區(qū)。費用合理售后完善,十余年實體公司更值得信賴。
執(zhí)行:
- select dd,count(*) from table group by dd having count(*)>1
如何用sql 查找兩個字段重復(fù)的記錄,并列出重復(fù)記錄
表名為CJB, 列出其中XH和KCMC字段都重復(fù)的記錄
執(zhí)行:
- select * from CJB a join (
- select XH,KCMC from CJB group by XH,KCMC
- having count(*)>1) b on a.XH=b.XH and a.KCMC=b.KCMC order by
- a.KCMC ,a.XH
實例:
- select productID,searchkay from shortkay group by searchkay,productID having count(*) > 1 order by searchkay
等同于下面這句:
- select a.ID,a.productID,a.searchkay from shortkay a join (select productID,searchkay from shortkay group by productID,
- searchkay having count(*)>1) b on a.productID=b.productID and a.searchkay=b.searchkay order by a.searchkay, a.productID
1、SQL Server查找表中多余的重復(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、SQL Server查找表中多余的重復(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)
以上的相關(guān)內(nèi)容就是對SQL Server查找和刪除重復(fù)記錄的方法的介紹,望你能有所收獲。
網(wǎng)頁標題:SQLServer查找與重復(fù)記錄的刪除方案描述
分享地址:http://www.dlmjj.cn/article/dhojegs.html


咨詢
建站咨詢
