Search code examples
sqlduplicatessql-deletegreenplum

How to delete the duplicates from the table using row_number() in psql?


I have written the following query, i am using greenplum db and dbeaver for implementation.

with cte as 
(select 
*, 
row_number() over(partition by first_name order by roll_num) row_num 
from table_name 
where roll_num in ('0011')) 
delete from cte where row_num>1;

The above query is returning error. Can someone help me here, please!


Solution

  • How about this:

    PostgreSQL DELETE statement with USING clause

    Ref: PostgreSQL Docs