0

From this SO POST Finding Duplicates, how can I delete 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 
Community
  • 1
  • 1
  • Do you mean "how can I DELETE duplicate rows from the base table" or "how can I ensure there are no duplicate rows in the output from SELECT"? They are two significantly different problems. The second is probably better termed 'eliminating duplicates (from a result set)' as DELETE has connotations of changing a table. – Jonathan Leffler Oct 05 '11 at 02:41

1 Answers1

1

just use the DISTINCT keyword:

SELECT DISTINCT firstname FROM list;

if any of the output is a duplicate, mysql will remove them.

for more documentation on DISTINCT go here:

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

Code Monkey
  • 319
  • 1
  • 7
  • not sure why you keep editing it, not to clear on what you want tho. if your looking to remove duplicates DISTINCT will take care of that. – Code Monkey Oct 05 '11 at 01:45