SQL語句實現刪除重覆記錄並只保留一條

2022-09-26 13:03:24 字數 2133 閱讀 1895

複製** **如下:

delete weibotopics where id in(select max(id) from weibotopics group by weiboid,title h**ing count(*) > 1);

sqwww.cppcns.coml:刪除重複資料,只保留一條用sql語句,刪除掉重複項只保留一條在幾千條記錄裡,存在著些相同的記錄,如何能用sql語句,刪除掉重複的呢

1、查詢表中多餘的重覆記錄,重覆記錄是根據單個字段(peopleid)來判斷

複製** **如下:

select * from people where peopleid in (select peopleid from people group by peopleid h**ing c > 1)

2、刪除表中多餘的重覆記錄,重覆記錄是根據單個字段(peopleid)來判斷,只留有rowid最小的記錄

複製** **如下:

delete from people where   peoplename in (select peoplename    from people group by peoplename程式設計客棧      h**ing count(peoplename) > 1) and   peopleid not in (select min(peopleid) from people group by peoplename     h**ing count(peoplename)>1)

3、查詢表中多餘程式設計客棧的重覆記錄(多個字段)

複製** **如下:

select * from vitae a where (a.peopleid,a.seq) in (select peopleid,seqwww.cppcns.com from vitae group by peopleid,seq h**ing count(*) > 1)

4、刪除表中多餘的重覆記錄(多個字段),只留有rowid最小的記錄

複製** **如下:

delete from vitae a where (a.peopleid,a.seq) in (select peopleid,seq from vitae group by peopleid,seq h**ing count(*) > 1) and rowid not in (select min(rowid) from vitae group by peopleid,seq h**ing count(*)>1)

5、查詢表中多餘的重覆記錄(多個字段),不包含rowid最小的記錄

複製** **如下:

select * from vitae a where (a.peopleid,a.seq) in (select peopleid,seq from vitae group by peopleid,seq h**ing count(*) > 1) and rowid not in (select min(rowid) from vitae group by peopleid,seq h**ing count(*)>1) 

6.消除乙個欄位的左邊的第一位:

複製** **如下:

update tablename set [title]=right([title],(len([title])-1)) where title like '村%'

7.消除乙個欄位的右邊的第一位:

複製** **如下:

update tablename set [title]=left([title],(len([title])-1)) where title like '%村'

8.假刪除表中多餘的重覆記錄(多個字段),不包含rowid最小的記錄

複製** **如下:

update vitae set ispass=-1 where peopleid in (select peopleid from vitae group by peopleid,seq h**ing count(*) > 1) and seq in (select seq from vitae group by peopleid,seq h**ing count(*) > 1) and rowid not in (select min(rowid) from vitae group by peopleid,seq h**ing count(*)>1)

本文標題: sql語句實現刪除重覆記錄並只保留一條

本文位址:

SQL 語句刪除access重覆記錄語句

有兩個意義上的重覆記錄,一是完全重複的記錄,也即所有欄位均重複的記錄,二是部分關鍵字段重複的記錄,比如name欄位重複,而其他欄位不一定重複或都重複可以忽略。1 對於第一種重複,比較容易解決,使用 select distinct from tablename 就可以得到無重覆記錄的結果集。如果該錶需...

通過SQL語句刪除重覆記錄

最近在專案裡碰到很多重覆記錄的事情,因為是設計業務裡的具體數值,所以不敢輕易全部刪除,資料量也很大,所以就倒騰了點 在sql裡進行刪除 純屬菜鳥,還望高手指教啊 1 建立臨時表23 ifexists select from tempdb.dbo.sysobjects whereid object i...

SQL查詢重覆記錄,刪除重覆記錄

1 查詢表中多餘的重覆記錄,重覆記錄是根據單個字段 docid 來判斷 select from tablename where docid in select docid from tablename group by docid h ing count docid 1 例二 select from...