删除重复项

时间:2011-10-05 01:31:21

标签: mysql

从这个SO POST Finding Duplicates,我该如何删除重复项。

SELECT firstname, lastname, list.address FROM list 
INNER JOIN (SELECT address FROM list 
GROUP BY address HAVING count(id) > 1) dup ON list.address = dup.address 

1 个答案:

答案 0 :(得分:1)

只需使用DISTINCT关键字:

SELECT DISTINCT firstname FROM list;

如果任何输出是重复的,mysql将删除它们。

有关DISTINCT的更多文档,请访问:

http://www.cyberciti.biz/faq/howto-removing-eliminating-duplicates-from-a-mysql-table/