我需要删除此表的重复值:
+----+-------+-------------+---------+
| id | name | description | surname |
+----+-------+-------------+---------+
| 1 | Peter | Member | Hitsh |
| 2 | James | Member | Tach |
| 3 | Mary | Member | Popims |
| 4 | Peter | Member | Hitsh |
+----+-------+-------------+---------+
我希望使用相同的name
和surname
删除所有重复的值。
答案 0 :(得分:0)
要为id
上的每组重复项保留最小(name, surname)
的行:
DELETE FROM tbl
USING (
SELECT id, row_number OVER (PARTITION BY name, surname ORDER BY id) As rn
FROM tbl
) del
WHERE tbl.id = del.id
AND del.rn > 1;
假设id
是唯一的。
今天非常相似的问题:
Delete all rows but one with the greatest value per group