Re: How should I do this?

From: Martijn van Oosterhout <kleptog(at)svana(dot)org>
To: Laurent Duperval <lduperval(at)videotron(dot)ca>
Cc: pgsql-general(at)postgresql(dot)org
Subject: Re: How should I do this?
Date: 2002-06-28 02:17:55
Message-ID: 20020628121755.A15733@svana.org
Views: Raw Message | Whole Thread | Download mbox | Resend email
Thread:
Lists: pgsql-general

On Thu, Jun 27, 2002 at 08:55:23PM -0400, Laurent Duperval wrote:
> On Thu, 27 Jun 2002 12:53:21 -0400, Martijn van Oosterhout wrote:
>
> > Have a look at DISTINCT ON. It works well for this sort of thing.
> >
>
> Yes, but if I have
>
> 1 2 3
> 2 2 3
> 3 3 4
> 4 2 3
> 5 2 3
>
> I want
>
> 1 2 3
> 3 3 4
> 4 2 3
>
> left in the database. I think using distint on would yield
>
> 1 2 3
> 3 3 4

Ah right. The problem is that DISTINCT ON requires that the fields be
distincted on be the same and the first few fields being sorted by. In the
hypothetical case you could do:

select distinct on (col2) select * from a order by col1;

But that isn't allowed. Maybe you will be a stored procedure or something.

--
Martijn van Oosterhout <kleptog(at)svana(dot)org> http://svana.org/kleptog/
> There are 10 kinds of people in the world, those that can do binary
> arithmetic and those that can't.

In response to

Responses

Browse pgsql-general by date

  From Date Subject
Next Message Justin Clift 2002-06-28 03:52:27 Suggestions for an update to the PHP manual?
Previous Message Curt Sampson 2002-06-28 02:17:28 Re: Shared Memory Sizing