1. 程式人生 > >MySQL數據去重

MySQL數據去重

log bold mysq pan sele 去重 join sql 重復

列出數據表中的重復數據:

SELECT name, COUNT(*) FROM product GROUP BY name HAVING COUNT(*) > 1;

刪除重復數據:

DELETE FROM products AS A JOIN(SELECT name, COUNT(*), MAX(id) AS id FROM products GROUP BY name HAVING COUNT(*) > 1) AS B ON A.name = B.name WHERE A.id < B.id;

MySQL數據去重