Re: Select Question - Mailing list pgsql-general

From Jeff Eckermann
Subject Re: Select Question
Date
Msg-id 20040202193842.98284.qmail@web20806.mail.yahoo.com
Whole thread Raw
In response to Re: Select Question  (Martijn van Oosterhout <kleptog@svana.org>)
Responses Re: Select Question  (Richard Huxton <dev@archonet.com>)
List pgsql-general
--- Martijn van Oosterhout <kleptog@svana.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);

You could write that as a join also.  I have found
little or no performance difference in the cases that
I have tested, although you may find otherwise.

BTW, I hope you are not really using "date" as a
column name.  That is too much trouble to be worth it.

>
> On Tue, Feb 03, 2004 at 12:22:29AM +0900, Alex
> wrote:
> > Hi,
> > I need to remove duplicate records from a table
> like
> >
> > Code         Date
> > XS111111     2004-01-26
> > XS111111     2003-01-22
> > XS222222     2004-02-01
> > XS222222     2004-01-26
> > XS222222     2003-01-22
> >
> > where only the newest record of Code XSxxxxxxx is
> kept in the table. Is
> > there an easy way to do that?
>
> --
> Martijn van Oosterhout   <kleptog@svana.org>
> http://svana.org/kleptog/
> > (... have gone from d-i being barely usable even
> by its developers
> > anywhere, to being about 20% done. Sweet. And the
> last 80% usually takes
> > 20% of the time, too, right?) -- Anthony Towns,
> debian-devel-announce
>

> ATTACHMENT part 2 application/pgp-signature



__________________________________
Do you Yahoo!?
Yahoo! SiteBuilder - Free web site building tool. Try it!
http://webhosting.yahoo.com/ps/sb/

pgsql-general by date:

Previous
From: Terry Lee Tucker
Date:
Subject: Re: Return Value of a Function
Next
From: "Peter Darley"
Date:
Subject: Transfer database tables to a schema