My Thoughts & Views

How To: Delete Duplicate Rows from a Table

Posted on: August 15, 2009


Problem: You have a table (table1) & values as above, and it contains the duplicate records as shown, how will you delete the duplicates?


Solution: Use following query, the records shown in the below image will be deleted

delete from table1 where empid not in
(select max(empid) from table1 group by empName,empEmail,empCity);

Advertisements

2 Responses to "How To: Delete Duplicate Rows from a Table"

hi kiran,1. the scenario is wrongwe find the employee id as different this is unique rows so not duplicate rows2. review the query

Hi Ram,If you dont have primary key column in your table, alter the table define a primary key column, delete it duplicate and again alter the table and remove the primary key column.Thanks 🙂

Leave a Reply

Fill in your details below or click an icon to log in:

WordPress.com Logo

You are commenting using your WordPress.com account. Log Out / Change )

Twitter picture

You are commenting using your Twitter account. Log Out / Change )

Facebook photo

You are commenting using your Facebook account. Log Out / Change )

Google+ photo

You are commenting using your Google+ account. Log Out / Change )

Connecting to %s

%d bloggers like this: