当Mysql表中只有一列时,如何删除重复项
如果表的行下面..
mysql> select * from EMP ;
+------+
| id |
+------+
| 10 |
| 10 |
| 10 |
| 20 |
| 20 |
| 30 |
+------+
删除重复项后,我需要行。
10
20
30
我不想使用任何其他临时表。需要删除查询以删除mysql中的重复项
答案 0 :(得分:1)
使用distinct
select distinct id from EM
您可以使用row_number()
删除重复项:
with todelete as (
select em.*, row_number() over (partition by id order by id) as seqnum
from em
)
delete from todelete
where seqnum > 1;