How to delete records in the table which are repeated?

前端 未结 6 1773
长情又很酷
长情又很酷 2021-01-25 03:35

Hi Here i came across a situation in which by mistakenly Without dropping the table i have run the batch file of the table which consists of some insert statements in detail

6条回答
  •  生来不讨喜
    2021-01-25 04:12

    To just delete the duplicate new rows and leave the old ones in place (on the basis that I assume there are already other tables whose rows refer to the original rows):-

    DELETE FROM alert_priority
    WHERE Id IN (SELECT MaxId
    FROM (SELECT priority_name, MAX(Id) AS MaxId, COUNT(Id)  AS CountId
    FROM alert_priority
    GROUP BY priority_name
    HAVING CountId > 1))
    

提交回复
热议问题