如何删除 MySQL 表上的重复项?

2021-11-20 00:00:00 duplicates mysql

我需要在 MySQL 表上DELETE 指定 sid 的重复行.

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

如何使用 SQL 查询执行此操作?

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.

推荐答案

这会在原地删除重复项,而无需创建新表

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

相关文章