我在表中有唯一的鍵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