我正在query
中使用以下PostgreSQL 10
查找重复条目:
select
column1, column2, count(*)
from mytable
where column3 in ('yes', 'no')
group by column1, column2 having count(*) > 2;
除了每个条目的第一个条目外,是否有可能PostgreSQL
删除重复项?
答案 0 :(得分:1)
假设您的表具有主键:
delete from mytable t
where t.pk <> (select min(t2.pk)
from mytable t2
where t2.column1 = t.column1 and
t2.column2 = t.column2 and
t2.column3 in ('yes', 'no')
);