Re: Select Question

From: Richard Huxton <dev(at)archonet(dot)com>
To: Jeff Eckermann <jeff_eckermann(at)yahoo(dot)com>, Martijn van Oosterhout <kleptog(at)svana(dot)org>, Alex <alex(at)meerkatsoft(dot)com>
Cc: pgsql-general(at)postgresql(dot)org
Subject: Re: Select Question
Date: 2004-02-02 20:43:00
Message-ID: 200402022043.00840.dev@archonet.com
Views: Raw Message | Whole Thread | Download mbox | Resend email
Thread:
Lists: pgsql-general

On Monday 02 February 2004 19:38, Jeff Eckermann wrote:
> --- Martijn van Oosterhout <kleptog(at)svana(dot)org> wrote:
> > See DISTINCT ON()
>
> Yes, for selecting. For deleting, probably something
> like:
>
> delete from table t1 where exists (select 1 from table
> t2 where t2.code = t1.code and t2.date > t1.date);

Quick note that Jeff's solution doesn't handle the situation where you have
codes with the same date. You don't say whether this is possible or not. If
it is, you'll need to distinguish between rows based on some other column.

--
Richard Huxton
Archonet Ltd

In response to

Browse pgsql-general by date

  From Date Subject
Next Message Alvaro Herrera 2004-02-02 21:23:51 Re: Postgresql 7.3 And Redhat Enterprise 3
Previous Message Peter Darley 2004-02-02 19:47:56 Transfer database tables to a schema