Re: Re: Restriction by grouping problem.

From: "Josh Berkus" <josh(at)agliodbs(dot)com>
To: Philip Warner <pjw(at)rhyme(dot)com(dot)au>
Cc: pgsql-sql(at)postgresql(dot)org
Subject: Re: Re: Restriction by grouping problem.
Date: 2001-07-28 00:19:22
Message-ID: web-92889@davinci.ethosmedia.com
Views: Raw Message | Whole Thread | Download mbox | Resend email
Thread:
Lists: 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 information technology josh(at)agliodbs(dot)com
and data management solutions (415) 565-7293
for law firms, small businesses fax 621-2533
and non-profit organizations. San Francisco

Responses

Browse pgsql-sql by date

  From Date Subject
Next Message Philip Warner 2001-07-28 01:31:51 Re: Re: Restriction by grouping problem.
Previous Message Jimmie Fulton 2001-07-27 22:29:27 RE: Database Design Question