0

例如,如果我有

+------------+-------------+
| something_1| something_2 |
+------------+-------------+
| 1          | a           |
| 2          | b           |
| 3          | a           |
| 4          | c           |
| 5          | b           |
| 6          | a           |
| 6          | d           |
| 6          | e           |
+------------+-------------+

我想要这个,删除不重复的数据:

+-------------+
| something_2 |
+-------------+
| a           |
| b           |    
+-------------+

谢谢,我想要它在mysql中,请

4

2 回答 2

2

这只会给你重复的字段:

SELECT something_2 FROM mytable
GROUP BY something_2
HAVING COUNT(*) > 1
于 2013-06-14T04:14:38.183 回答
1

假设您的表有一个主键,请执行以下操作:

DELETE FROM my_table WHERE prim_key IN (SELECT prim_key FROM my_table
GROUP BY something_2
HAVING COUNT(*) > 1)
于 2013-06-14T04:18:12.967 回答