Friday, 22 April 2016

How to find and delete duplicate records in a table ?


For that Firstly check if table has duplicate records or not , using below query
SELECT firstName FROM emp
GROUP BY firstName
  HAVING COUNT(*) > 1

Then Delete duplicate records
DELETE FROM emp
WHERE id NOT IN (
  SELECT MAX(id) FROM emp GROUP BY firstName
)

No comments:

Post a Comment

Note: only a member of this blog may post a comment.