我正在尝试从mysql数据库中删除重复记录。使用以下命令,它将删除所有重复项并保留一行。在我的数据库中有300,000条记录,我希望有大约100,000行是重复的。
重复项需要通过以下命令删除,但问题是,我在9小时后的晚上发出命令它仍在运行。
DELETE n1 FROM tableA n1,tableA n2 WHERE n1.title= n2.title AND n1.id > n2.id
发生了什么事?谁能解释一下?
答案 0 :(得分:2)
尝试:
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
);