For each key, find row with highest value of other field

From: Raj Mathur <raju(at)linux-delhi(dot)org>
To: pgsql-sql(at)postgresql(dot)org
Subject: For each key, find row with highest value of other field
Date: 2008-10-03 18:55:31
Message-ID: 200810040025.31398.raju@linux-delhi.org
Views: Raw Message | Whole Thread | Download mbox | Resend email
Thread:
Lists: pgsql-sql

I have some data of the form:

Key | Date | Value
A | 2008-05-01 | foo *
A | 2008-04-01 | bar
A | 2008-03-01 | foo *
B | 2008-03-04 | baz
B | 2008-02-04 | bar
C | 2008-06-03 | foo *
C | 2008-04-04 | baz
C | 2008-03-04 | bar

Is there any way to select only the rows marked with a (*) out of these
without doing a join? I.e. I wish to find the row with the highest
Date for each Key and use the Value from that.

Regards,

-- Raju
--
Raj Mathur raju(at)kandalaya(dot)org http://kandalaya.org/
GPG: 78D4 FC67 367F 40E2 0DD5 0FEF C968 D0EF CC68 D17F
PsyTrance & Chill: http://schizoid.in/ || It is the mind that moves

Responses

Browse pgsql-sql by date

  From Date Subject
Next Message Oliveiros Cristina 2008-10-03 19:11:40 Re: For each key, find row with highest value of other field
Previous Message Marc Mamin 2008-10-03 12:20:45 Re: Query how-to