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 04E9D9FA5C8 for ; Thu, 1 Jun 2006 15:39:56 -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 51504-02 for ; Thu, 1 Jun 2006 15:39:51 -0300 (ADT) X-Greylist: domain auto-whitelisted by SQLgrey- Received: from ug-out-1314.google.com (ug-out-1314.google.com [66.249.92.170]) by postgresql.org (Postfix) with ESMTP id D12809FA040 for ; Thu, 1 Jun 2006 15:39:50 -0300 (ADT) Received: by ug-out-1314.google.com with SMTP id a2so200773ugf for ; Thu, 01 Jun 2006 11:39:48 -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:content-transfer-encoding:content-disposition:references:x-google-sender-auth; b=G0seU4AgeAOuArpjrjkO/x4DS482gDguukRkvNRk6ob/pOAzWBmgVJGosQ+b/bOoEbqkIurZY+WjA8SNy0uEUWLXCkChO0ctD8aTivXPccTS9bj42rcyCRgXcfo/j2NPUGC2rQ9feFONNCCymVl37+gxStCZINpv77yYdiCJmx0= Received: by 10.67.89.6 with SMTP id r6mr29735ugl; Thu, 01 Jun 2006 11:39:48 -0700 (PDT) Received: by 10.67.20.12 with HTTP; Thu, 1 Jun 2006 11:39:48 -0700 (PDT) Message-ID: Date: Thu, 1 Jun 2006 13:39:48 -0500 From: "Aaron Bono" To: "Yasir Malik" Subject: Re: Am I crazy or is this SQL not possible Cc: PostgreSQL In-Reply-To: MIME-Version: 1.0 Content-Type: text/plain; charset=ISO-8859-1; format=flowed Content-Transfer-Encoding: 7bit Content-Disposition: inline References: X-Google-Sender-Auth: 14b50933fb15ed58 X-Virus-Scanned: Maia Mailguard 1.0.1 X-Archive-Number: 200606/47 X-Sequence-Number: 25283 I think this approach will only work if each broadcast_id has the same maximum date_sent value. You really need to do the group by in a sub-query to bring the broadcast_id together with the max date_sent. On 6/1/06, Yasir Malik wrote: > > What I would like to do is simply get the last date_sent and it's > > status for every broadcast. I can't do a GROUP BY because I can't put > > an aggregate on the status column. > > > > SELECT MAX(date_sent), status > > FROM broadcast_history > > GROUP BY broadcast_id > > > You could try the following: > select status > from broadcast_history bh > where bh.date_sent = > (select max(bh2.date_sent) > from broadcast_history bh2); > ================================================================== Aaron Bono President Aranya Software Technologies, Inc. http://www.aranya.com We take care of your technology needs. Phone: (816) 695-6071 ==================================================================