Deleting duplicates rows from redshift

后端 未结 7 2016
南方客
南方客 2020-12-31 02:45

I am trying to delete some duplicate data in my redshift table.

Below is my query:-

With duplicates
As
(Select *, ROW_NUMBER() Over (PARTITION by rec         


        
7条回答
  •  情书的邮戳
    2020-12-31 02:52

    The following deletes all records in 'tablename' that have a duplicate, it will not deduplicate the table:

    DELETE FROM tablename
    WHERE id IN (
        SELECT id
        FROM (
              SELECT id,
              ROW_NUMBER() OVER (partition BY column1, column2, column3 ORDER BY id) AS rnum
              FROM tablename
             ) t
         WHERE t.rnum > 1);
    

    Postgres administrative snippets

提交回复
热议问题