Find and remove duplicate rows by two columns

前端 未结 7 687
鱼传尺愫
鱼传尺愫 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:30

    You will first need to find your duplicates by grouping on the two fields with a having clause.

        Select identField1, identField2, count(*) FROM yourTable
            GROUP BY identField1, identField2
              HAVING count(*) >1
    

    If this returns what you want, you can then use it as a subquery and

      DELETE FROM yourTable WHERE field in (Select identField1, identField2, count(*) FROM yourTable
            GROUP BY identField1, identField2
              HAVING count(*) >1 )
    

提交回复
热议问题