Re: Improve a query... - Mailing list pgsql-general

From Tom Lane
Subject Re: Improve a query...
Date
Msg-id 10304.988780664@sss.pgh.pa.us
Whole thread Raw
In response to Improve a query...  ("Eric G. Miller" <egm2@jps.net>)
Responses Re: Improve a query...  ("Eric G. Miller" <egm2@jps.net>)
List pgsql-general
"Eric G. Miller" <egm2@jps.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

pgsql-general by date:

Previous
From: pmh@edison.ioppublishing.com
Date:
Subject: Re: wierd problems with DBI/DBD::pg?
Next
From: "Christian Marschalek"
Date:
Subject: RE: Ideal hardware configuration for pgsql