【发布时间】:2011-05-07 12:52:01
【问题描述】:
我的表中有唯一键 id 键,但我有一列包含重复值?我如何摆脱这些,同时像这样只保留其中一个:
重复记录:
id | name | surname |
1 | test | one |
2 | test | two |
3 | test3 | three |
4 | test7 | four |
5 | test | five |
6 | test11 | eleven |
没有重复:
id | name | surname |
1 | test | one |
3 | test3 | three |
4 | test7 | four |
6 | test11 | eleven |
我已经用谷歌搜索了这个,但它似乎不起作用:
DELETE ct1
FROM mytable ct1
, mytable ct2
WHERE ct1.name = ct2.name
AND ct1.id < ct2.id
ERROR: syntax error at or near "ct1"
LINE 1: DELETE ct1
^
********** Error **********
我正在使用 postgres 数据库。
【问题讨论】:
-
清理完数据后,您可能需要对“名称”设置唯一约束。
标签: sql postgresql