
15 Jan
2008
15 Jan
'08
9:56 a.m.
Thomas Van Parys schreef:
Kenny Billiau schreef:
Hi,
just to test our MySQL vigilance, here's a simple challenge: You've got a table with rows that could contain some data twice. Show me a query that removes (or selects) the data that's been entered twice, keeping one copy!
For example, a simple table with 2 two fields: id and name. 'id' Is auto incrementing and name could be inserted twice or more. 1 thomas 2 thomas 3 thomas 4 michiel 5 sofie 6 michiel 7 kenny 8 elisabeth 9 michiel 10 sofie
First one to solve it, I'll buy a beer :)
SELECT MIN(id), name FROM nice_table GROUP BY name;
DELETE FROM nice_table WHERE id NOT IN (SELECT MIN(id) FROM nice_table GROUP BY name); Beer me! (really)