How to remove duplicate records in a table?

后端 未结 3 1857
离开以前
离开以前 2020-12-21 11:15

I\'ve got a table in a testing DB that someone apparently got a little too trigger-happy on when running INSERT scripts to set it up. The schema looks like this:

         


        
3条回答
  •  庸人自扰
    2020-12-21 11:33

    here is a great article on that: Deleting duplicates, which basically uses this pattern:

    WITH    q AS
            (
            SELECT  d.*,
                    ROW_NUMBER() OVER (PARTITION BY id ORDER BY value) AS rn
            FROM    t_duplicate d
            )
    DELETE
    FROM    q
    WHERE   rn > 1
    
    SELECT  *
    FROM    t_duplicate
    

提交回复
热议问题