Received: from localhost (unknown [200.46.204.183]) by postgresql.org (Postfix) with ESMTP id A0EAF2E008F for ; Sat, 29 Mar 2008 02:27:23 -0300 (ADT) Received: from postgresql.org ([200.46.204.71]) by localhost (mx1.hub.org [200.46.204.183]) (amavisd-maia, port 10024) with ESMTP id 85619-07-4 for ; Sat, 29 Mar 2008 02:27:21 -0300 (ADT) X-Greylist: from auto-whitelisted by SQLgrey-1.7.5 Received: from smtp104.sbc.mail.re2.yahoo.com (smtp104.sbc.mail.re2.yahoo.com [68.142.229.101]) by postgresql.org (Postfix) with SMTP id 01C992E009C for ; Sat, 29 Mar 2008 02:05:39 -0300 (ADT) Received: (qmail 94323 invoked from network); 29 Mar 2008 05:05:35 -0000 DomainKey-Signature: a=rsa-sha1; q=dns; c=nofws; s=s1024; d=sbcglobal.net; h=Received:X-YMail-OSG:X-Yahoo-Newman-Property:From:To:References:In-Reply-To:Subject:Date:Message-ID:MIME-Version:Content-Type:Content-Transfer-Encoding:X-Mailer:Thread-Index:Content-Language; b=XtWVQhAvI+7kGcWWnyiV7uTXn6D+S9URdA80iLl4JxuuUBjdQ3xf0FdxeXqxiWAaEDq0gJi2Ea4Z3yRdVvo2FFyb4o2p0KG9/YVlcQnmVuTigjokwZr088ulk/FxLSd7mXTC5284IGZwEkwm+jjUdz8gP7UOp2ZUGYpQNuYxDec= ; Received: from unknown (HELO dualcore) (adam.r@sbcglobal.net@68.251.53.133 with login) by smtp104.sbc.mail.re2.yahoo.com with SMTP; 29 Mar 2008 05:05:35 -0000 X-YMail-OSG: NqlfbWEVM1mQRZiLCCevWo.6HABjgFrcKkk6_Jke4AobyflBAm_8x..mdulvLdHgQuPr8yPO8QwtVNamM96BLLBC_L2j45iklso7Sk5SXpzscmV6d_nk402JCpIV3g-- X-Yahoo-Newman-Property: ymail-3 From: "Adam Rich" To: "'kevin kempter'" , References: <69712BCF-F10A-4874-BD7D-9A40E1474E19@kevinkempterllc.com> In-Reply-To: <69712BCF-F10A-4874-BD7D-9A40E1474E19@kevinkempterllc.com> Subject: Re: SQL question Date: Sat, 29 Mar 2008 00:03:33 -0500 Message-ID: <06a901c8915a$3d46e680$b7d4b380$@r@sbcglobal.net> MIME-Version: 1.0 Content-Type: text/plain; charset="us-ascii" Content-Transfer-Encoding: 7bit X-Mailer: Microsoft Office Outlook 12.0 Thread-Index: AciRWcChBdZDUM6tQ1ul8xUze8fVMwAAD97g Content-Language: en-us X-Virus-Scanned: Maia Mailguard 1.0.1 X-Spam-Status: No, hits=0.375 tagged_above=0 required=5 tests=AWL=-0.836, MSGID_MULTIPLE_AT=1.211 X-Spam-Level: X-Archive-Number: 200803/1520 X-Sequence-Number: 130842 > I have a table that has 3 date columns : > > create table xyz ( > xyz_id integer, > date1 timestamp, > date2 timestamp, > date3 timestamp > ) > > > I want to select in a query the xyz_id and the max date column for > each row > something like : > create table temp2 as select xyz_id (max date?) where ... Is this what you want? Select xyz_id, greatest(date1,date2,date3) from xyz where... http://www.postgresql.org/docs/8.3/interactive/functions-conditional.html#AE N14508