X-Original-To: pgsql-sql-postgresql.org@localhost.postgresql.org Received: from localhost (mx1.hub.org [200.46.208.251]) by postgresql.org (Postfix) with ESMTP id 118299FA5D2 for ; Thu, 1 Jun 2006 15:29:13 -0300 (ADT) Received: from postgresql.org ([200.46.204.71]) by localhost (mx1.hub.org [200.46.208.251]) (amavisd-new, port 10024) with ESMTP id 44211-08 for ; Thu, 1 Jun 2006 15:29:09 -0300 (ADT) X-Greylist: from auto-whitelisted by SQLgrey- Received: from floppy.pyrenet.fr (floppy.pyrenet.fr [194.116.145.2]) by postgresql.org (Postfix) with ESMTP id 143319FA040 for ; Thu, 1 Jun 2006 15:29:08 -0300 (ADT) Received: by floppy.pyrenet.fr (Postfix, from userid 106) id 2985031DC3; Thu, 1 Jun 2006 20:29:08 +0200 (MET DST) From: "maTKO" X-Newsgroups: pgsql.sql Subject: Re: Am I crazy or is this SQL not possible Date: 1 Jun 2006 11:29:01 -0700 Organization: http://groups.google.com Lines: 16 Message-ID: <1149186541.453106.45070@i39g2000cwa.googlegroups.com> References: Mime-Version: 1.0 Content-Type: text/plain; charset="iso-8859-1" X-Complaints-To: groups-abuse@google.com User-Agent: G2/0.2 X-HTTP-UserAgent: Mozilla/5.0 (Windows; U; Windows NT 5.1; en-US; rv:1.8.0.3) Gecko/20060426 Firefox/1.5.0.3,gzip(gfe),gzip(gfe) Complaints-To: groups-abuse@google.com Injection-Info: i39g2000cwa.googlegroups.com; posting-host=83.131.54.149; posting-account=Sm7Aow0AAAC3ylQ4JGYCd64xnzvtvm67 To: pgsql-sql@postgresql.org X-Virus-Scanned: Maia Mailguard 1.0.1 X-Archive-Number: 200606/45 X-Sequence-Number: 25281 "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;