Re: [GENERAL] Selecting duplicates - Mailing list pgsql-general

From Herbert Liechti
Subject Re: [GENERAL] Selecting duplicates
Date
Msg-id 37AAA0EA.76C909DF@thinx.ch
Whole thread Raw
List pgsql-general
--
~Adriaan Joubert wrote:

> Gary Hoffman wrote:
> >
> > Somehow, I've managed to get duplicate entries in my soon-to-be primary
> > key field. How can I select for duplicates in a field? I know how to
> > select for blank and NULL, but duplicates escape me.
>
> Sorry, I only know complicated ways of doing this. The way I usually do
> it is to create a temporary table:
>
> create temp table tmp (id int4, cnt int4);
> insert into tmp select id, count(*) from <table> group by id;

The easier way

    select field_with_duplicates, count(*) from table
      group by field_with_duplicate having count(*) > 1;

Greatings Herbie

--
~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
Herbert Liechti                            E-Mail: Herbert.Liechti@thinx.ch
ThinX networked business services               Stahlrain 10, CH-5200 Brugg
~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~


pgsql-general by date:

Previous
From: Yury Don
Date:
Subject: Re: [GENERAL] Selecting duplicates
Next
From: "Nationale HaFaBra-site"
Date:
Subject: Perl DBD?