Received: from localhost (unknown [200.46.204.184]) by postgresql.org (Postfix) with ESMTP id 1A5F52E37D1 for ; Mon, 7 Jan 2008 19:18:14 -0400 (AST) Received: from postgresql.org ([200.46.204.71]) by localhost (mx1.hub.org [200.46.204.184]) (amavisd-maia, port 10024) with ESMTP id 67013-04 for ; Mon, 7 Jan 2008 19:17:53 -0400 (AST) Received: from smtp166.iad.emailsrvr.com (smtp166.iad.emailsrvr.com [207.97.245.166]) by postgresql.org (Postfix) with ESMTP id 264412E3002 for ; Mon, 7 Jan 2008 19:18:08 -0400 (AST) Received: from relay6.relay.iad.emailsrvr.com (localhost [127.0.0.1]) by relay6.relay.iad.emailsrvr.com (SMTP Server) with ESMTP id CCF666F4191; Mon, 7 Jan 2008 18:18:06 -0500 (EST) Received: by relay6.relay.iad.emailsrvr.com (Authenticated sender: erik-AT-myemma.com) with ESMTP id 8FB366EC7D4; Mon, 7 Jan 2008 18:18:06 -0500 (EST) In-Reply-To: References: <4782A1B2.5050804@encs.concordia.ca> <1199745537.5877.9.camel@godzilla.local.scalefeather.com> Mime-Version: 1.0 (Apple Message framework v752.3) Content-Type: text/plain; charset=ISO-8859-1; delsp=yes; format=flowed Message-Id: <53C367DF-24B3-425C-9EE7-BBA7336D3A89@myemma.com> Cc: "Josh Williams" , emilu@encs.concordia.ca, pgsql-sql@postgresql.org Content-Transfer-Encoding: quoted-printable From: Erik Jones Subject: Re: Get the max(value1, value2, value3) from a table Date: Mon, 7 Jan 2008 17:16:58 -0600 To: Scott Marlowe X-Mailer: Apple Mail (2.752.3) X-Virus-Scanned: Maia Mailguard 1.0.1 X-Archive-Number: 200801/43 X-Sequence-Number: 29896 On Jan 7, 2008, at 4:43 PM, Scott Marlowe wrote: > On Jan 7, 2008 4:38 PM, Josh Williams wrote: >> On Mon, 2008-01-07 at 17:03 -0500, Emi Lu wrote: >>> select ?max?(col1, col2, col3) as result; >>> will return >>> >>> result >>> ------- >>> 5 >>> 8 >>> 12 >>> >>> (3 rows) >> >> 8.1 (I believe?) introduced GREATEST(), which does precisely what =20 >> you're >> looking for. > > How would greatest give him three rows like that? Maybe I'm > misunderstanding what the OP was asking for... His test data was: col1 col2 col3 ---------------------- 1 5 2 8 1 3 12 1 1 So, SELECT test(col1, col2, col3); returning test ----- 5 8 12 Is giving the max of the three columns for each row. Erik Jones DBA | Emma=AE erik@myemma.com 800.595.4401 or 615.292.5888 615.292.0777 (fax) Emma helps organizations everywhere communicate & market in style. Visit us online at http://www.myemma.com