MySQL数据去重

列出数据表中的重复数据:

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;

 

posted @ 2018-02-24 21:26  右威卫大将军  阅读(161)  评论(0编辑  收藏  举报