Re: Improve a query...
Eric G. Miller <egm2@jps.net>
From: "Eric G. Miller" <egm2@jps.net>
To: PostgreSQL General <pgsql-general@postgresql.org>
Date: 2001-05-03T01:04:44Z
Lists: pgsql-general
On Wed, May 02, 2001 at 07:30:13PM +0200, Peter Eisentraut wrote: > 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; Naw, doesn't work. I need the other columns, so the GROUP BY is out (except in a subselect). The DISTINCT ON () syntax, though non-standard, seems to do the job. -- Eric G. Miller <egm2@jps.net>