From: Josh Berkus <josh@agliodbs.com>
To: Philip Warner <pjw@rhyme.com.au>
Cc: pgsql-sql@postgresql.org
Subject: Re: Re: Restriction by grouping problem.
Date: Fri, 27 Jul 2001 17:19:22 -0700
Message-ID: <web-92889@davinci.ethosmedia.com> (raw)
In-Reply-To: <3.0.5.32.20010728100308.02c98800@mail.rhyme.com.au>
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@agliodbs.com
and data management solutions (415) 565-7293
for law firms, small businesses fax 621-2533
and non-profit organizations. San Francisco
Reply instructions:
You may reply publicly to this message via plain-text email
using any one of the following methods:
* Reply to all the recipients using the --to and --cc options:
reply via email
To: pgsql-sql@postgresql.org
Cc: josh@agliodbs.com, pjw@rhyme.com.au
Subject: Re: Re: Restriction by grouping problem.
In-Reply-To: <web-92889@davinci.ethosmedia.com>
* Save the following mbox file, import it into your mail client,
and reply-to-all from there: mbox
This inbox is served by DDX for PostgreSQL; see mirroring instructions
for how to clone and mirror all data and code used for this inbox