i have duplicates like this
col1, col2
1, alex
1, alex
2, liza
2, liza
3, peter
3, peter
there are only two of each. how do i delete the duplicates?
i have duplicates like this
col1, col2
1, alex
1, alex
2, liza
2, liza
3, peter
3, peter
there are only two of each. how do i delete the duplicates?
WITH    q AS
        (
        SELECT  *,
                ROW_NUMBER() OVER (PARTITION BY col1, col2 ORDER BY col1, col2) AS rn
        FROM    mytable
        )
DELETE
FROM    q
WHERE   rn >= 2
See here:
 
    
    If the origin table is not huge.
select distinct * from origin_table into temp_table;
truncate table origin_table;
insert into origin_table select * from temp_table ;
drop table temp_table;
 
    
    insert into table_new
   Select col1, col2, min(pk) as pk from table_old
   group by col1, col2
-- debug table_new
drop table_old
