I want to delete duplicate records in table x, and I executed a query saying:
delete from x where col1 in ( select col1 from x group by col1 having count(*)>1)It is deleting all the records in table that have duplicate col1 values, but my problem is that I want one record to stay.
Deleting records would not be a problem if you had a primary key on your table. The absence of a PK constraint leads to this exact problem. If you had a PK on the table, then you could delete by the PK columns to uniquely identify a row.
But a solution to your problem is not too difficult. This solution has elegantly been posted on Tom Kyte's AskTom Web site. Rather than duplicate the work, I'll give you the URL below for your solution:
Dig Deeper on Oracle database design and architecture
Have a question for an expert?
Please add a title for your question
Get answers from a TechTarget expert on whatever's puzzling you.