欢迎您访问程序员文章站本站旨在为大家提供分享程序员计算机编程知识!
您现在的位置是: 首页

删除数据库中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)