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 263D29FA1A8 for ; Fri, 2 Jun 2006 12:23:41 -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 81211-09 for ; Fri, 2 Jun 2006 12:23:32 -0300 (ADT) X-Greylist: domain auto-whitelisted by SQLgrey- Received: from ug-out-1314.google.com (ug-out-1314.google.com [66.249.92.168]) by postgresql.org (Postfix) with ESMTP id 0E6AD9FA5C4 for ; Fri, 2 Jun 2006 12:23:31 -0300 (ADT) Received: by ug-out-1314.google.com with SMTP id a2so525709ugf for ; Fri, 02 Jun 2006 08:23:30 -0700 (PDT) DomainKey-Signature: a=rsa-sha1; q=dns; c=nofws; s=beta; d=gmail.com; h=received:message-id:date:from:sender:to:subject:cc:in-reply-to:mime-version:content-type:references:x-google-sender-auth; b=Bj044loOI/9W2JPDhOhQw6LlkRy4UunEdJhpY2ntADBzSSdyHFnkNkNSR4NR/hd0+sdAKzg3bez7e3/j2oxAHITndcbS+DDPs/2UzjxQAS1rYnzMLeFNOmY00aKRRWlFyYBBFYenTA/+IZKdyDgiQGmyZc1ajLPjkF2KstpfmTM= Received: by 10.67.106.3 with SMTP id i3mr883364ugm; Fri, 02 Jun 2006 08:23:30 -0700 (PDT) Received: by 10.67.20.12 with HTTP; Fri, 2 Jun 2006 08:23:30 -0700 (PDT) Message-ID: Date: Fri, 2 Jun 2006 10:23:30 -0500 From: "Aaron Bono" To: "Klay Martens" Subject: Re: Am I crazy or is this SQL not possible Cc: patrick.jacquot@anpe.fr, cadiolis@gmail.com, pgsql-sql@postgresql.org In-Reply-To: <6c800ab64b48492fa88fa92f4fc28625@wol.co.za> MIME-Version: 1.0 Content-Type: multipart/alternative; boundary="----=_Part_9859_3719310.1149261810349" References: <6c800ab64b48492fa88fa92f4fc28625@wol.co.za> X-Google-Sender-Auth: 3f7ac401625ca46c X-Virus-Scanned: Maia Mailguard 1.0.1 X-Archive-Number: 200606/39 X-Sequence-Number: 25275 ------=_Part_9859_3719310.1149261810349 Content-Type: text/plain; charset=ISO-8859-1; format=flowed Content-Transfer-Encoding: 7bit Content-Disposition: inline Only if you assume that ordering by unique_id and by date_sent are equivalent. That may be the case but I personally hate making assumptions like that. When someone goes into the database and updates records (clean up bad data, etc.) your perfectly running query can suddenly produce bad results. -Aaron On 6/2/06, Klay Martens wrote: > > > Sorry to stick my nose in here... > would not this work better? > > SELECT broadcast_id,date_sent,status from broadcast_history where > unique_id in ( > SELECT max(unique_id) from broadcast_history group by broadcast_id); > > Seems like a simpler option. > ------=_Part_9859_3719310.1149261810349 Content-Type: text/html; charset=ISO-8859-1 Content-Transfer-Encoding: 7bit Content-Disposition: inline Only if you assume that ordering by unique_id and by date_sent are equivalent.  That may be the case but I personally hate making assumptions like that.  When someone goes into the database and updates records (clean up bad data, etc.) your perfectly running query can suddenly produce bad results.

-Aaron

On 6/2/06, Klay Martens <kmartens@wol.co.za> wrote:

Sorry to stick my nose in here...
would not this work better?

SELECT broadcast_id,date_sent,status from broadcast_history where
unique_id in (
SELECT max(unique_id) from broadcast_history group by broadcast_id);

Seems like a simpler option.

 

------=_Part_9859_3719310.1149261810349--