Re: Am I crazy or is this SQL not possible

From: "maTKO" <matko(dot)andjelinic(at)gmail(dot)com>
To: pgsql-sql(at)postgresql(dot)org
Subject: Re: Am I crazy or is this SQL not possible
Date: 2006-06-01 18:29:01
Message-ID: 1149186541.453106.45070@i39g2000cwa.googlegroups.com
Views: Raw Message | Whole Thread | Download mbox | Resend email
Thread:
Lists: 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;

In response to

Browse pgsql-sql by date

  From Date Subject
Next Message Aaron Bono 2006-06-01 18:38:03 Re: Am I crazy or is this SQL not possible
Previous Message Yasir Malik 2006-06-01 18:13:40 Re: Am I crazy or is this SQL not possible