Received: from localhost (maia-2.hub.org [200.46.204.187]) by postgresql.org (Postfix) with ESMTP id 9837C9F9DB4 for ; Mon, 13 Aug 2007 17:17:00 -0300 (ADT) Received: from postgresql.org ([200.46.204.71]) by localhost (mx1.hub.org [200.46.204.187]) (amavisd-maia, port 10024) with ESMTP id 42343-05 for ; Mon, 13 Aug 2007 17:16:47 -0300 (ADT) X-Greylist: domain auto-whitelisted by SQLgrey-1.7.5 Received: from an-out-0708.google.com (an-out-0708.google.com [209.85.132.243]) by postgresql.org (Postfix) with ESMTP id 728D79F9D30 for ; Mon, 13 Aug 2007 17:16:50 -0300 (ADT) Received: by an-out-0708.google.com with SMTP id c36so255601ana for ; Mon, 13 Aug 2007 13:16:49 -0700 (PDT) DKIM-Signature: a=rsa-sha1; c=relaxed/relaxed; d=gmail.com; s=beta; h=domainkey-signature:received:received:message-id:date:from:to:subject:cc:in-reply-to:mime-version:content-type:content-transfer-encoding:content-disposition:references; b=GWy8hHjG/bJXQDhgP77XSG+e2YOTbessA03cehVml+kcAgDaBBDGUy4AY/fa9rTFXHFCjRsHzPk2vpr+rFrcAFnmBjCa9LCflXyAKPeRLyuKlWfubAP+MJWrtMnwzNDGI8aOmNMnGUj0Ph06z+teyNFobNAdYroTIOgOfBZ0Hr8= DomainKey-Signature: a=rsa-sha1; c=nofws; d=gmail.com; s=beta; h=received:message-id:date:from:to:subject:cc:in-reply-to:mime-version:content-type:content-transfer-encoding:content-disposition:references; b=XT1sF6HLUC+sGOdG6qPPrQOEBNfRUrZYNrPf5yhKHhyo0OVJGp+D5daK6IX0IhOYdg+7iJQ1tI4jkJWLyP/1Tn+BkMXI7pMGGtTdZ/Jq9ibmPFy3u4J9amIvAE4hBjLnT7qMJio3ZAwxm4roxk69sQZxT/R96hmKP2bP8dbFZP8= Received: by 10.100.154.13 with SMTP id b13mr5336936ane.1187036209120; Mon, 13 Aug 2007 13:16:49 -0700 (PDT) Received: by 10.100.33.20 with HTTP; Mon, 13 Aug 2007 13:16:49 -0700 (PDT) Message-ID: Date: Mon, 13 Aug 2007 15:16:49 -0500 From: "=?UTF-8?Q?Rodrigo_De_Le=C3=B3n?=" To: "Bryce Nesbitt" Subject: Re: Getting pk of the most recent row, in a group by Cc: pgsql-sql@postgresql.org In-Reply-To: <46C0B994.6090906@obviously.com> MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 7bit Content-Disposition: inline References: <46C0B994.6090906@obviously.com> X-Virus-Scanned: Maia Mailguard 1.0.1 X-Archive-Number: 200708/116 X-Sequence-Number: 29054 On 8/13/07, Bryce Nesbitt wrote: > In the second example, is it possible to get the primary key of the row > with the minimum expires time? SELECT TYPE, MIN(expires), COUNT(*) , (SELECT MIN(coupon_id) FROM coupon WHERE expires = MIN(c.expires)) AS coupon_id FROM coupon c GROUP BY TYPE;