如何从MySQL表中删除重复的值

问题描述:

我正在寻找查询,删除所有重复的值.

i am looking for the query, deletes the all duplicate values.

Example Table:

1 ABC
2 BBB
3 DAC
4 ABC
5 AAA
6 ABC

output required

1 ABC
2 BBB
3 DAC
5 AAA

感谢您的帮助,Google找不到确切的解决方案.

thanks for your help, i Google it can't find exact solution.

如果要对重复值进行实际的DELETE操作(同时保留具有最低id的值),则可以使用多表DELETE语法:

If you want to do an actual DELETE operation of the duplicate values (while retaining the values having the lowest id), you can do it with the multiple table DELETE syntax:

DELETE a FROM tbl a
LEFT JOIN
(
    SELECT MIN(id) AS id, name
    FROM tbl
    GROUP BY name
) b ON a.id = b.id AND a.name = b.name
WHERE b.id IS NULL