select distinct on - Mailing list pgsql-general

From Dave Ahn
Subject select distinct on
Date
Msg-id 20001120171615.A417229@cecum.vec.wfubmc.edu
Whole thread Raw
Responses Re: select distinct on  (Tom Lane <tgl@sss.pgh.pa.us>)
List pgsql-general
Hello,

I am trying to use SELECT DISTINCT ON.  This works as intended:
    SELECT DISTINCT ON (f1) * from table ORDER BY f1

 f1 | f2 | f3
----+----+----
  1 |  2 |  3
  2 |  2 |  2
  3 |  1 |  2

However, I am trying to order the results by non-distinct fields f2, f3
to get:

 f1 | f2 | f3
----+----+----
  3 |  1 |  2
  2 |  2 |  2
  1 |  2 |  3

Clearly this does not work:
    SELECT DISTINCT ON (f1) * from table ORDER BY f2, f3, f1

So is there some other way without SELECT INTO a temporary table?
Thanks in advance.
Dave
--
Dave Ahn | ahn@vec.wfubmc.edu | Wake Forest University Baptist Medical Center

When you were born, you cried and the world rejoiced.  Try to live your life
so that when you die, you will rejoice and the world will cry.  -1/2 jj^2

pgsql-general by date:

Previous
From: Peter Eisentraut
Date:
Subject: Re: posible documentation error.
Next
From: "Willis, Ian (Ento, Canberra)"
Date:
Subject: RE: External Large objects what became of them