select distinct on

From: Dave Ahn <ahn(at)vec(dot)wfubmc(dot)edu>
To: pgsql-general(at)postgresql(dot)org
Subject: select distinct on
Date: 2000-11-20 22:16:15
Message-ID: 20001120171615.A417229@cecum.vec.wfubmc.edu
Views: Raw Message | Whole Thread | Download mbox | Resend email
Thread:
Lists: 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(at)vec(dot)wfubmc(dot)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

Responses

Browse pgsql-general by date

  From Date Subject
Next Message Willis, Ian (Ento, Canberra) 2000-11-20 22:24:37 RE: External Large objects what became of them
Previous Message Peter Eisentraut 2000-11-20 22:07:41 Re: posible documentation error.