From: Aaron Bono <postgresql@aranya.com>
To: Tom Lane <tgl@sss.pgh.pa.us>
Cc: pgsql-sql@postgresql.org
Subject: Re: Am I crazy or is this SQL not possible
Date: Thu, 1 Jun 2006 20:44:18 -0500
Message-ID: <bf05e51c0606011844s5553241ev144934da7e52f5f0@mail.gmail.com> (raw)
In-Reply-To: <14505.1149189691@sss.pgh.pa.us>
References: <df01c91b0606011043g61328d6habaee8fa037a5ccf@mail.gmail.com>
<14505.1149189691@sss.pgh.pa.us>
Is this SQL-99 compliant or a PostgreSQL specific query? I really like it
and have never seen this before.
-Aaron
On 6/1/06, Tom Lane <tgl@sss.pgh.pa.us> wrote:
>
> "Collin Peters" <cadiolis@gmail.com> writes:
> > What I would like to do is simply get the last date_sent and it's
> > status for every broadcast. I can't do a GROUP BY because I can't put
> > an aggregate on the status column.
>
> You missed the key idea about how to use DISTINCT ON.
>
> SELECT DISTINCT ON (email_broadcast_id) *
> FROM email_broadcast_history
> ORDER BY email_broadcast_id, date_sent DESC
>
> You order by the DISTINCT ON fields, then one or more additional fields
> to select the representative row you want within each DISTINCT ON group.
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: postgresql@aranya.com, tgl@sss.pgh.pa.us
Subject: Re: Am I crazy or is this SQL not possible
In-Reply-To: <bf05e51c0606011844s5553241ev144934da7e52f5f0@mail.gmail.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