我在表中有唯一的键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 |
我GOOGLE了这一点,但它似乎没有要工作:
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数据库。
当你清理完数据后,你可能需要在“name”上加上一个UNIQUE约束。 – 2011-05-08 03:18:33