表刪除重覆記錄 小記

2021-06-19 16:07:33 字數 554 閱讀 5158

刪除資料庫中重覆記錄方法:

表test_loge

有兩個字段,乙個是

id,乙個是

name

,我們需要刪除多餘的行

1、使用rowid

(保留rowid

最大的值)

delete from test_loge a where rowid !=(select max(rowid) from test_loge b where a.id=b.id ,...);

或則delete from loge where rowid not in (  select max(rowid)   from loge t group by t.col1, t.col2);

2、使用distince

1) 建立臨時表,create table temp as select distinct  * from test_loge;

2) 刪除原表,truncate table test_loge

3) 建立插入原表,insert into test_loge select *

from temp;

刪除重覆記錄

我們經常在資料庫中有重複的記錄這時候我們希望刪除那些重複的記錄 你不要告訴我你是一條條手動刪除的哈 select distinct into newtable form 程式設計客棧nbsp tablename drop table tabwww.cppcns.comlename select in...

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

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

如何刪除表中重覆記錄?

最近專案中遇到了乙個需求,即 如何刪除表中重覆記錄,使得所有重複的記錄都只保留一行?在google了半個小時之後,發現居然沒有乙個是正常可用的,於是乎只好自己動手寫了乙個。因為即便是grails提供了很好的gorm,但是使用sql仍然不可能完全避免,因此把它共享出來,也符合咱們 的 共享開發經驗 的...