删除重复行(不要删除所有重复行) [英] Delete duplicate rows (don't delete all duplicate)
本文介绍了删除重复行(不要删除所有重复行)的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!
问题描述
我正在使用 postgres.我想删除重复的行.条件是,不会删除重复行集中的 1 个副本.
I am using postgres. I want to delete Duplicate rows. The condition is that , 1 copy from the set of duplicate rows would not be deleted.
即:如果有 5 条重复记录,则将删除其中的 4 条.
i.e : if there are 5 duplicate records then 4 of them will be deleted.
推荐答案
尝试本文中描述的步骤:从 PostgreSQL 数据库中删除重复项.
Try the steps described in this article: Removing duplicates from a PostgreSQL database.
它描述了一种情况,当您必须处理无法分组
的大量数据时.
It describes a situation when you have to deal with huge amount of data which isn't possible to group by
.
一个简单的解决方案是:
A simple solution would be this:
DELETE FROM foo
WHERE id NOT IN (SELECT min(id) --or max(id)
FROM foo
GROUP BY hash)
其中 hash
是重复的东西.
Where hash
is something that gets duplicated.
这篇关于删除重复行(不要删除所有重复行)的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!
查看全文