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 B5D7D9FA5D2 for ; Thu, 1 Jun 2006 15:31:12 -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 50656-03 for ; Thu, 1 Jun 2006 15:31:04 -0300 (ADT) X-Greylist: delayed 00:17:18.646886 by SQLgrey- Received: from guinness.cs.stevens-tech.edu (guinness.cs.stevens-tech.edu [155.246.89.8]) by postgresql.org (Postfix) with ESMTP id 727179FA040 for ; Thu, 1 Jun 2006 15:31:03 -0300 (ADT) Received: from pink-elephant.cs.stevens.edu (pink-elephant.cs.stevens-tech.edu [155.246.81.117]) by guinness.cs.stevens-tech.edu (Postfix) with ESMTP id 09D5B164C1 for ; Thu, 1 Jun 2006 14:13:41 -0400 (EDT) Received: by pink-elephant.cs.stevens.edu (Postfix, from userid 4405) id BA6C71EF36B; Thu, 1 Jun 2006 14:13:40 -0400 (EDT) Received: from localhost (localhost [127.0.0.1]) by pink-elephant.cs.stevens.edu (Postfix) with ESMTP id 8B37E1EF2F3 for ; Thu, 1 Jun 2006 14:13:40 -0400 (EDT) Date: Thu, 1 Jun 2006 14:13:40 -0400 (EDT) From: Yasir Malik X-X-Sender: ymalik@pink-elephant.cs.stevens-tech.edu To: PostgreSQL Subject: Re: Am I crazy or is this SQL not possible In-Reply-To: Message-ID: References: MIME-Version: 1.0 Content-Type: TEXT/PLAIN; charset=US-ASCII; format=flowed X-Virus-Scanned: Maia Mailguard 1.0.1 X-Archive-Number: 200606/19 X-Sequence-Number: 25255 > 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); This reminds me of an interview question: I was asked how to get a maximum column from a table without using max. How would you do that? Thanks, Yasir