How to delete duplicates on a MySQL table?

Ali Demirci picture Ali Demirci · Apr 13, 2010 · Viewed 218.9k times · Source

I need to DELETE duplicated rows for specified sid on a MySQL table.

How can I do this with an SQL query?

DELETE (DUPLICATED TITLES) FROM table WHERE SID = "1"

Something like this, but I don't know how to do it.

Answer

user187291 picture user187291 · Apr 13, 2010

this removes duplicates in place, without making a new table

ALTER IGNORE TABLE `table_name` ADD UNIQUE (title, SID)

note: only works well if index fits in memory