我正在尝试从mysql数据库中删除重复记录。使用下面的命令,它将删除所有重复项并保留一行。在我的数据库中有300,000条记录,我预计大约有100,000行是重复的。
下面的命令需要删除重复项,但问题是,我在晚上给出了该命令,它仍然运行了9个小时。
DELETE n1 FROM tableA n1,tableA n2 WHERE n1.title= n2.title AND n1.id > n2.id这是怎么回事?有谁能解释一下吗?
发布于 2012-10-06 13:39:03
正在尝试:
select * from tableA as n1 join tableA as n2 on n1.title = n2.title AND n1.id > n2.id;解释一下:n1.title = n2.title不使用索引。
下面的查询会更好:
delete from `t2` where `id` in (
select cid from (
select max(id) as cid from t2 group by title having count(*) > 1
) as c
);https://stackoverflow.com/questions/12756800
复制相似问题