Thread: Re: [GENERAL] Selecting duplicates

Re: [GENERAL] Selecting duplicates

From
Herbert Liechti
Date:
--
~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
~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~