Re: Re: Restriction by grouping problem. - Mailing list pgsql-sql

From Josh Berkus
Subject Re: Re: Restriction by grouping problem.
Date
Msg-id web-92889@davinci.ethosmedia.com
Whole thread Raw
In response to Restriction by grouping problem.  ("Jeff Barrett" <jbarrett@familynetwork.com>)
Responses Re: Re: Restriction by grouping problem.  (Philip Warner <pjw@rhyme.com.au>)
List pgsql-sql
Phillip,

> What it effectively does is executes the second SELECT for each row
> of the
> first select, a bit like a column-select expression, but it allows
> access
> to all rows.

Ah!  I knew that there had to be a simple way to do what you want to do
in PGSQL:

SELECT MIN(getfile) as bestfile
FROM logs,   (SELECT SID, MAX(logtime) as lasttime FROM logs) MDT
WHERE logs.SID = MDT.SID   AND logs.logtime = MDT.lasttime
GROUP BY SID

This gives you the "getfile" from the logs with the latest timestamp.
In the event of two with the exact same logtime, it selects the first
one alphabetically so that you don't get two files for one SID.

-Josh

______AGLIO DATABASE SOLUTIONS___________________________                                      Josh Berkus Complete
informationtechnology      josh@agliodbs.com  and data management solutions       (415) 565-7293 for law firms, small
businesses       fax 621-2533   and non-profit organizations.      San Francisco
 


pgsql-sql by date:

Previous
From: Jimmie Fulton
Date:
Subject: RE: Database Design Question
Next
From: Philip Warner
Date:
Subject: Re: Re: Restriction by grouping problem.