sql语句:
delete from table where ctid not in (select min(ctid) from table group by tableColumn)
其中:
- table是数据表表名, tableColumn是判断数据是否重复的关键列,根据情况替换;
- ctid是postgres中的关键字,不可替换。
- 可以将min(ctid)换成max(ctid),如果需要保存的是最新插入的数据,使用max
sql语句:
delete from table where ctid not in (select min(ctid) from table group by tableColumn)
其中: