Wednesday, July 30, 2014

Query to find the Duplicates in the Table and Delete them.

Use the below Query to find the duplicates in the table :

SELECT *
FROM TABLE_NAME A
WHERE A.ROWID IN
(SELECT MIN(B.ROWID)
FROM TABLE_NAME B
WHERE
A.COLUMN1=B.COLUMN1
GROUP BY B.COLUMN1,B.COLUMN2);

Use the below Query to delete the duplicates in the table :

DELETE
FROM TABLE_NAME A
WHERE A.ROWID IN
(SELECT MIN(B.ROWID)
FROM TABLE_NAME B
WHERE
A.COLUMN1=B.COLUMN1
GROUP BY B.COLUMN1,B.COLUMN2);

No comments:

Post a Comment