我在M $ Access中有一个重复的表格,如:
NAME
----------------
Charlie
Anderson Silva
Minotauro
Cigano
Sonnen
Charlie
Charlie
Minotauro
Anderson Silva
如何删除此表中的重复项并仅保留每个唯一名称?
类似的东西:
NAME
----------------
Charlie
Anderson Silva
Minotauro
Cigano
Sonnen
只是在DELETE中使用SELECT来“分组”吗?如果是的话,会是怎样的?谢谢!
答案 0 :(得分:1)
SELECT
MIN(ID) AS ID, Name
FROM
TableName
GROUP BY
Name
这将给出每个名称的最小ID
1 | Charlie |
2 | Anderson |
3 | Mino |
等
所以你可以
DELETE TableName WHERE ID NOT IN
(
SELECT
MIN(ID) AS ID
FROM
TableName
GROUP BY
Name
)