Skip to content
Advertisement

Deleting duplicates on combination of two columns in oracle

I have a table for example : Port Table

S No A Port B port
1 80 100
2 90 110
3 100 80
4 94 106

I want to delete record no. 3 as it is having same combination as record no. 1 how to do this in oracle ?

Advertisement

Answer

You can use a single MERGE statement and the ROW_NUMBER analytic function combined with GREATEST and LEAST to find and delete the duplicates:

Which, for your sample data:

Will delete the 3rd row.

db<>fiddle here

User contributions licensed under: CC BY-SA
9 People found this is helpful
Advertisement