Received: from maia.hub.org (maia-3.hub.org [200.46.204.243]) by mail.postgresql.org (Postfix) with ESMTP id B0533B5DBE0 for ; Thu, 22 Sep 2011 23:59:18 -0300 (ADT) Received: from mail.postgresql.org ([200.46.204.86]) by maia.hub.org (mx1.hub.org [200.46.204.243]) (amavisd-maia, port 10024) with ESMTP id 60048-08 for ; Fri, 23 Sep 2011 02:59:12 +0000 (UTC) X-Greylist: delayed 00:09:47.82708 by SQLgrey-1.8.0-rc2 Received: from newserver.jfcomputer.com (unknown [76.14.161.106]) by mail.postgresql.org (Postfix) with ESMTP id 2DD2EB5DBD1 for ; Thu, 22 Sep 2011 23:59:12 -0300 (ADT) Received: from localhost (unknown [127.0.0.1]) by newserver.jfcomputer.com (Postfix) with ESMTP id 6BE6B1236B for ; Fri, 23 Sep 2011 02:49:22 +0000 (UTC) X-Virus-Scanned: amavisd-new at site Received: from newserver.jfcomputer.com ([127.0.0.1]) by localhost (linux-jfp8.site [127.0.0.1]) (amavisd-new, port 10024) with ESMTP id COC7nBND+Zmn for ; Thu, 22 Sep 2011 19:49:21 -0700 (PDT) Received: from linux-desktop.localnet (unknown [192.168.1.108]) (using TLSv1 with cipher DHE-RSA-AES256-SHA (256/256 bits)) (No client certificate requested) (Authenticated sender: johnf@jfcomputer.com) by newserver.jfcomputer.com (Postfix) with ESMTPSA id 0167A4ED6 for ; Thu, 22 Sep 2011 19:49:20 -0700 (PDT) From: John Fabiani Organization: J.F. Computer Solutions To: "pgsql-sql@postgresql.org" Subject: using the aggregate function max() Date: Thu, 22 Sep 2011 19:49:20 -0700 User-Agent: KMail/1.13.5 (Linux/2.6.34.10-0.2-desktop; KDE/4.4.4; i686; ; ) MIME-Version: 1.0 Content-Type: text/plain; charset="us-ascii" Content-Transfer-Encoding: 7bit Message-Id: <201109221949.20671.johnf@jfcomputer.com> X-Virus-Scanned: Maia Mailguard 1.0.1 X-Spam-Status: No, hits=-1.107 tagged_above=-5 required=5 tests=BAYES_00=-1.9, RDNS_NONE=0.793 X-Spam-Level: X-Archive-Number: 201109/65 X-Sequence-Number: 35865 Hi, I need a little help understanding how to attack this problem. I need to find the max(date) of a field but I need that value later in my query. If I select max(x.date_field) as special_date from (select date_field) from table where ...)x I get one row and column. But now I want to use that field in the rest of the query select y.*, max(x.date_field) as special_date from (select date_field) from table where ...)x from aTable y where y.somefield = special_date. The above only returns one row and one column the "special_date." How can I use the aggregate field "special_date" in the rest of the query? Or is there some other way? Johnf