Q
Problem solve Get help with specific problems with your technologies, process and projects.

Deleting duplicates

I want to delete the duplicate records from table and keep only one record.

Example: ID Name
1 Sinu, 2 Sinu, 3 Sinu, 4 Tinu, 5 Tinu

Output
1 Sinu, 4 Tinu


Having a unique ID makes this easy. By using a self referencing sub-query and the MIN aggregate function, you can determine the lowest ID for a given NAME. By deleting all but the lowest ID, you are left with a unique set of NAMEs.

delete from MyTable t1
  where id <> ( select min(ID) from MyTable t2 
                  where t2.Name = t1.Name )

For More Information


Dig Deeper on Oracle and SQL

Have a question for an expert?

Please add a title for your question

Get answers from a TechTarget expert on whatever's puzzling you.

You will be able to add details on the next page.

Start the conversation

Send me notifications when other members comment.

Please create a username to comment.

-ADS BY GOOGLE

SearchDataManagement

SearchBusinessAnalytics

SearchSAP

SearchSQLServer

TheServerSide.com

SearchDataCenter

SearchContentManagement

SearchHRSoftware

Close