Re: [GENERAL] Selecting duplicates

From: Herbert Liechti <Herbert(dot)Liechti(at)thinx(dot)ch>
To: postgres <pgsql-general(at)hub(dot)org>
Subject: Re: [GENERAL] Selecting duplicates
Date: 1999-08-06 08:46:34
Message-ID: 37AAA0EA.76C909DF@thinx.ch
Views: Raw Message | Whole Thread | Download mbox | Resend email
Thread:
Lists: 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(dot)Liechti(at)thinx(dot)ch
ThinX networked business services Stahlrain 10, CH-5200 Brugg
~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~

Browse pgsql-general by date

  From Date Subject
Next Message Roberto Moreda 1999-08-06 09:46:23 What is R_PLANS?
Previous Message Yury Don 1999-08-06 08:19:24 Re: [GENERAL] Selecting duplicates