--- Martijn van Oosterhout <kleptog@svana.org> wrote:[color=blue]
> See DISTINCT ON()[/color]
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.
[color=blue]
>
> On Tue, Feb 03, 2004 at 12:22:29AM +0900, Alex
> wrote:[color=green]
> > Hi,
> > I need to remove duplicate records from a table[/color]
> like[color=green]
> >
> > 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[/color]
> kept in the table. Is[color=green]
> > there an easy way to do that?[/color]
>
> --
> Martijn van Oosterhout <kleptog@svana.org>
>
http://svana.org/kleptog/[color=green]
> > (... have gone from d-i being barely usable even[/color]
> by its developers[color=green]
> > anywhere, to being about 20% done. Sweet. And the[/color]
> last 80% usually takes[color=green]
> > 20% of the time, too, right?) -- Anthony Towns,[/color]
> debian-devel-announce
>[/color]
[color=blue]
> ATTACHMENT part 2 application/pgp-signature[/color]
__________________________________
Do you Yahoo!?
Yahoo! SiteBuilder - Free web site building tool. Try it!
http://webhosting.yahoo.com/ps/sb/
---------------------------(end of broadcast)---------------------------
TIP 8: explain analyze is your friend