Re: query for non-unique values?

From: Kevin Brannen <kevinb(at)nurseamerica(dot)net>
To: Andy Kriger <akriger(at)greaterthanone(dot)com>
Cc: Pgsql-General <pgsql-general(at)postgresql(dot)org>
Subject: Re: query for non-unique values?
Date: 2002-09-23 22:26:12
Message-ID: 3D8F9504.3020906@nurseamerica.net
Views: Raw Message | Whole Thread | Download mbox | Resend email
Thread:
Lists: pgsql-general

Andy Kriger wrote:
> I have a file of legacy data that has duplicate entries in a column that I'd
> like to have a unique index on. How can I query to find the duplicates (so I
> can determine if they can be thrown out)?

If you have yet to learn about self joins, this is a great example of
where they are handy. Assuming a table like:

create table abc
(
id int not null, -- primary key
name text, -- duplicates are here
);

Try something like:

select b.*
from abc a, abc b
where a.id < b.id
and a.name = b.name;

HTH,
Kevin

In response to

Browse pgsql-general by date

  From Date Subject
Next Message Elaine Lindelef 2002-09-23 22:28:36 Re: OID order = INSERT order?
Previous Message pilsl 2002-09-23 22:15:47 Re: bug(?) : order by function limit x