pg.ddx.io  pgsql-sql@postgresql.org mailing list archive  
help / color / mirror / Atom feed
From: maTKO <matko.andjelinic@gmail.com>
To: pgsql-sql@postgresql.org
Subject: Re: Am I crazy or is this SQL not possible
Date: 1 Jun 2006 11:29:01 -0700
Message-ID: <1149186541.453106.45070@i39g2000cwa.googlegroups.com> (raw)
References: <df01c91b0606011043g61328d6habaee8fa037a5ccf@mail.gmail.com>

"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;




view thread (20+ messages)  latest in thread

Message-ID: <1149186541.453106.45070@i39g2000cwa.googlegroups.com>
Permalink:  ../1149186541.453106.45070@i39g2000cwa.googlegroups.com/
Also on:    postgresql.org/message-id/1149186541.453106.45070@i39g2000cwa.googlegroups.com

 · 

reply

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: matko.andjelinic@gmail.com
  Subject: Re: Am I crazy or is this SQL not possible
  In-Reply-To: <1149186541.453106.45070@i39g2000cwa.googlegroups.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