Re: Am I crazy or is this SQL not possible - Mailing list pgsql-sql

From maTKO
Subject Re: Am I crazy or is this SQL not possible
Date
Msg-id 1149186541.453106.45070@i39g2000cwa.googlegroups.com
Whole thread Raw
In response to Am I crazy or is this SQL not possible  ("Collin Peters" <cadiolis@gmail.com>)
List pgsql-sql
"Collin Peters" wrote:
> DISTINCT also doesn't work
>
> SELECT DISTINCT ON (email_broadcast_id) *
> FROM email_broadcast_history
> ORDER BY date_sent
>
> As you have to have the DISTINCT fields matching the ORDER BY fields.
> I have to ORDER BY date_sent, but I can't do a DISTINCT on date_sent

DISTINCT does work. You don't have to do DISTINCT on date_sent. The
left part of the ORDER BY must match the DISTINCT expression(s):

SELECT DISTINCT ON(broadcast_id) broadcast_id, date_sent, status FROM
table ORDER BY broadcast_id, date_sent DESC;



pgsql-sql by date:

Previous
From: "Thomas Chille"
Date:
Subject: Re: distinct aggregate with complex type dont see the equality operator [solved]
Next
From: "Aaron Bono"
Date:
Subject: Re: Am I crazy or is this SQL not possible