0

I'm using the following query in PostgreSQL 10 to find dublicate entries:

select
  column1, column2, count(*)
from mytable
  where column3 in ('yes', 'no')
group by column1, column2 having count(*) > 2;

Is it possible to have PostgreSQL delete the dublicates except of course the first of each entry?

1
  • Sample data and desired results would be helpful. Commented Jul 2, 2019 at 11:27

1 Answer 1

1

Assuming your table has a primary key:

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')
                  );
Sign up to request clarification or add additional context in comments.

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.