Re: Improve a query...

From: Tom Lane <tgl(at)sss(dot)pgh(dot)pa(dot)us>
To: "Eric G(dot) Miller" <egm2(at)jps(dot)net>
Cc: PostgreSQL General <pgsql-general(at)postgresql(dot)org>
Subject: Re: Improve a query...
Date: 2001-05-02 05:17:44
Message-ID: 10304.988780664@sss.pgh.pa.us
Views: Raw Message | Whole Thread | Download mbox | Resend email
Thread:
Lists: pgsql-general

"Eric G. Miller" <egm2(at)jps(dot)net> writes:
> Looking for the best way to formulate a query to select
> the most "recent" entry for an organization in a table
> like:

Take a look at the SELECT reference page's example for
SELECT DISTINCT ON:

: For example,
:
: SELECT DISTINCT ON (location) location, time, report
: FROM weatherReports
: ORDER BY location, time DESC;
:
: retrieves the most recent weather report for each location.

A tad nonstandard, but bloody effective, particularly if you
have an appropriate index in place...

regards, tom lane

In response to

Responses

Browse pgsql-general by date

  From Date Subject
Next Message Tom Lane 2001-05-02 05:22:10 Re: Re: do functions cache views?
Previous Message Justin Clift 2001-05-02 05:02:37 Re: Serial Type