Mysql 查重复,删除重复记录
How To Delete Duplicate Rows in MySQL
# 查重
SELECT
entry_id,
COUNT(entry_id)
FROM
uniprot_entries
GROUP BY
entry_id
HAVING
COUNT(entry_id) > 1;
# 删除重复的数据<巨慢,不推荐>
DELETE c1 FROM uniprot_entries c1
INNER JOIN uniprot_entries c2
WHERE
c1.id > c2.id AND
c1.entry_id = c2.entry_id;
# 人肉方式, 删除重复的
BEGIN;
DELETE FROM uniprot_entries where id in (308281, 110922, 333043);
COMMIT;
# 一次性删除,删除重复的(分3步执行)
BEGIN;
DELETE FROM uniprot_entries where id in (
-- 查重
select t.id from (SELECT
id
FROM
uniprot_entries
GROUP BY
entry_id
HAVING
COUNT(entry_id) > 1) t
);
COMMIT;