Reputation: 111
For example, If I have
+------------+-------------+
| something_1| something_2 |
+------------+-------------+
| 1 | a |
| 2 | b |
| 3 | a |
| 4 | c |
| 5 | b |
| 6 | a |
| 6 | d |
| 6 | e |
+------------+-------------+
I want this, deleting the no-duplicates data:
+-------------+
| something_2 |
+-------------+
| a |
| b |
+-------------+
Thanks, I want it in mysql, please
Upvotes: 0
Views: 45
Reputation: 17871
This will give you only the duplicate fields:
SELECT something_2 FROM mytable
GROUP BY something_2
HAVING COUNT(*) > 1
Upvotes: 2
Reputation: 2605
Let's suppose you have a primary key for your table, do the following:
DELETE FROM my_table WHERE prim_key IN (SELECT prim_key FROM my_table
GROUP BY something_2
HAVING COUNT(*) > 1)
Upvotes: 1