删除数据库中id重复的记录
程序员文章站
2022-06-02 13:02:51
...
一条SQL删除数据库中id重复的记录
oracle数据库执行
delete from table_name where table_name.rowid not in(select max(rowid) from table_name group by id);
postgresql数据库执行
delete from table_name where vulnerability.ctid not in(select max(ctid) from table_name group by id);
postgresql数据库也可以使用一下语句去重【推荐】
DELETE from table_name as a WHERE a.ctid <> (select max(b.ctid) from table_name as b where a.id = b.id)