Re: Deleting all but one row of a list of non-uniques - Mailing list pgsql-general

From Martijn van Oosterhout
Subject Re: Deleting all but one row of a list of non-uniques
Date
Msg-id 20040623004137.GA30207@svana.org
Whole thread Raw
In response to Deleting all but one row of a list of non-uniques  (Zak McGregor <zak@mighty.co.za>)
List pgsql-general
On Wed, Jun 23, 2004 at 02:17:50AM +0200, Zak McGregor wrote:
> Hi all
>
>
> I have a table, for simplicity's sake containing one field, called unid.

<snip>

> (I've marked the rows with duplicated unids with the * to the right)
>
> I'd like to delete rows in such a way that one (and any one) row for each unid
> remains, and all other duplicates are removed. Does anyone have any ideas that
> may help me here please?

The usual scheme I use is something like: (not perfect SQL)

delete from table where exists (select from table where this.id <
that.id).

Hope this helps,
--
Martijn van Oosterhout   <kleptog@svana.org>   http://svana.org/kleptog/
> Patent. n. Genius is 5% inspiration and 95% perspiration. A patent is a
> tool for doing 5% of the work and then sitting around waiting for someone
> else to do the other 95% so you can sue them.

Attachment

pgsql-general by date:

Previous
From: Zak McGregor
Date:
Subject: Deleting all but one row of a list of non-uniques
Next
From: Scott Ribe
Date:
Subject: Re: Connection gets into state where all queries fail