Re: [GENERAL] Improve a query...

2001-05-02 Thread Peter Eisentraut
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/

RE: [GENERAL] Improve a query...

2001-05-02 Thread Jeff Eckermann
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

Re: [GENERAL] Improve a query...

2001-05-02 Thread Tom Lane
"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