Find and remove duplicate rows by two columns

前端 未结 7 590
鱼传尺愫
鱼传尺愫 2021-02-01 08:52

I read all the relevant duplicated questions/answers and I found this to be the most relevant answer:

INSERT IGNORE INTO temp(MAILING_ID,REPORT_ID) 
SELECT DISTI         


        
7条回答
  •  伪装坚强ぢ
    2021-02-01 09:28

    The best way to delete duplicate rows by multiple columns is the simplest one:

    Add an UNIQUE index:

    ALTER IGNORE TABLE your_table ADD UNIQUE (field1,field2,field3);
    

    The IGNORE above makes sure that only the first found row is kept, the rest discarded.

    (You can then drop that index if you need future duplicates and/or know they won't happen again).

提交回复
热议问题