Eric G. Miller writes:
> If max(period) for an organization yields the most recent reporting,
> I want to get whatever is the most recent report for each organization.
SELECT org_id, max(period) FROM reports GROUP BY org_id;
--
Peter Eisentraut [EMAIL PROTECTED] http://funkturm.homeip.net/
Try:
SELECT DISTINCT ON (org_id) rpt_id, org_id, period,...
FROM reports
ORDER BY period DESC;
> -Original Message-
> From: Eric G. Miller [SMTP:[EMAIL PROTECTED]]
> Sent: Tuesday, May 01, 2001 4:04 AM
> To: PostgreSQL General
> Subject: [GENERAL] Improve a query...
>
> Looking fo
"Eric G. Miller" <[EMAIL PROTECTED]> 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 (loca