1

Possible Duplicate:
How to delete duplicate records in mysql database?

there are duplicate rows in the mysql table. how find the duplicate rows and delete them.

Community
  • 1
  • 1
kush
  • 93
  • 2
  • 10

3 Answers3

3

My preferred solution:

How to delete duplicate records in mysql database?

In the future, use unique/primary keys to make sure this doesn't happen again.

Community
  • 1
  • 1
Michael B
  • 1,743
  • 4
  • 21
  • 35
2

Define the columns that you want to use to determine duplication and add a unique index on them.

ALTER IGNORE TABLE table_name ADD UNIQUE INDEX (c1,c2,c3);

This has the advantage of preventing future duplicates.

Ray Baxter
  • 3,181
  • 23
  • 27
-1

DELETE * ,count(*)as n FROMaddgroup by id HAVING n>1 .

It will delete all duplicate records

Nitish
  • 2,695
  • 9
  • 53
  • 88
  • -1 for several reasons: intention is different from original question (he wants to remove the duplicates (and keep the 'original'), you delete everything) but mostly because your MySQL statement is invalid SQL. Check the manual at http://dev.mysql.com/doc/refman/5.0/en/delete.html . You are not allowed to use GROUP BY in a DELETE statement. – Eljakim Jul 12 '11 at 09:04