mysql怎麼重複資料刪除記錄

來源:互聯網
上載者:User
mysql

表名是tongxunlu 欄位是id sXingMing sXingBie dtShengRi
因為重複插入了,幾份資料,想重複資料刪除的


回複討論(解決方案)

舉例說明,怎麼判斷重複的。

手動刪除。。

可以直接判斷sXingMing sXingBie dtShengRi這幾個欄位值是否相同,然後再根據需要進行刪除

重複資料刪除記錄

delete from tongxunlu a where  rowid not in(select max(rowid) from tongxunlu where id=a.id and sXingMing=a.sXingMing and  sXingBie=a. sXingBie and dtShengRi=a.dtShengRi); 

delete from tongxunlu  where  id not in(select max(id) from tongxunlu group by id sXingMing sXingBie dtShengRi;


以什麼為判斷重複的條件,則以什麼分組。

先說多少條資料。
資料不多的話,把資料表備份出來,原來的表清空,foreach掃一遍備份資料表,把不重複的的插入到原來的表中。
這樣就解決問題了,沒必要搞那麼高深。

才幾份資料,用第三方工具直接刪了。

delete from tb1 where id in(select id,count(id) as tt from tb.where having tt>1)
執行肯定是要花費一定的時間的,關鍵看資料量多少

delete from tb1 where id in(select id,count(id) as tt from tb.where having tt>1 group by $fn )
掉了group by

學習了


放飛心情 技術人生

  • 聯繫我們

    該頁面正文內容均來源於網絡整理,並不代表阿里雲官方的觀點,該頁面所提到的產品和服務也與阿里云無關,如果該頁面內容對您造成了困擾,歡迎寫郵件給我們,收到郵件我們將在5個工作日內處理。

    如果您發現本社區中有涉嫌抄襲的內容,歡迎發送郵件至: info-contact@alibabacloud.com 進行舉報並提供相關證據,工作人員會在 5 個工作天內聯絡您,一經查實,本站將立刻刪除涉嫌侵權內容。

    A Free Trial That Lets You Build Big!

    Start building with 50+ products and up to 12 months usage for Elastic Compute Service

    • Sales Support

      1 on 1 presale consultation

    • After-Sales Support

      24/7 Technical Support 6 Free Tickets per Quarter Faster Response

    • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.