Re: order by, but eliminating dupes

From: Bruno Wolff III <bruno(at)wolff(dot)to>
To: LH <_pgsql-novice_(at)geekhouse(dot)no-ip(dot)com>
Cc: pgsql-novice(at)postgresql(dot)org
Subject: Re: order by, but eliminating dupes
Date: 2003-09-04 03:19:32
Message-ID: 20030904031932.GA28420@wolff.to
Views: Raw Message | Whole Thread | Download mbox | Resend email
Thread:
Lists: pgsql-novice

On Wed, Sep 03, 2003 at 22:52:44 -0400,
LH <_pgsql-novice_(at)geekhouse(dot)no-ip(dot)com> wrote:
> So lets say I got a table A(x,y,z, Q) ordered by column Q, with contents
> like so:
>
> But that kills the order of the subquery. I've tried group by x,y,z but
> then I can't ORDER BY Q.

I think you can do something like this:

select x, y, z from
(select distinct on (x, y, z) x, y, z, q order by x, y, z, q)
order by q;

In response to

Browse pgsql-novice by date

  From Date Subject
Next Message Tom Lane 2003-09-04 03:22:50 Re: Using NOT IN
Previous Message glenn 2003-09-04 02:54:48 Editing functions