SQL to delete the duplicates in a table

后端 未结 3 1717
失恋的感觉
失恋的感觉 2021-01-14 13:08

I have a table transaction which has duplicates. i want to keep the record that had minimum id and delete all the duplicates based on four fields DATE, AMOUNT, REFNUMBER, PA

3条回答
  •  不要未来只要你来
    2021-01-14 13:28

    DELETE FROM transaction
          WHERE ID IN (
                   SELECT ID
                     FROM (SELECT ID,
                              ROW_NUMBER () OVER (PARTITION BY  date
                                                              ,amount
                                                              ,refnumber
                                                              ,parentfolderid
                                                    ORDER BY ID) rn
                                                  FROM transaction)
                    WHERE rn <> 1);
    

    I will try like this

提交回复
热议问题