Received: from demai02.mw.mediaone.net (demai02.mw.mediaone.net [24.131.1.20]) by hub.org (8.9.1/8.9.1) with ESMTP id UAA11696 for ; Wed, 2 Dec 1998 20:46:00 -0500 (EST) (envelope-from adam@maddock.com) Received: from apu.maddock.net (nic-c28-211.mw.mediaone.net [24.131.28.211]) by demai02.mw.mediaone.net (8.8.7/8.8.7) with SMTP id UAA21575; Wed, 2 Dec 1998 20:45:01 -0500 (EST) Date: Wed, 2 Dec 1998 20:45:52 -0500 (EST) From: Adam Maddock X-Sender: adam@apu.maddock.net To: Greg Youngblood cc: "'PostgreSQL SQL List'" Subject: Re: [SQL] Please help: How to determine largest of two numbers in a query? In-Reply-To: <2B9713A99045D211BB4E0008C75668692EA70C@SCORPEXC1.houstoncell.com> Message-ID: MIME-Version: 1.0 Content-Type: TEXT/PLAIN; charset=US-ASCII Greg - This may not be the slickest way to do it, but it works... SELECT yyyymmdd, key, value1 AS value FROM greg WHERE value1 > value2 UNION SELECT yyyymmdd, key, value2 AS value FROM greg WHERE value2 > value1; I hope this helps. :-) Blessings, Adam ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~ Adam Maddock http://Adam.Maddock.com Detroit, MI adam@maddock.com "BE IMITATORS of God, therefore, as dearly loved children..." (Ephesians 5:1) ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~ On Wed, 2 Dec 1998, Greg Youngblood wrote: > I have a table with the following structure: > yyyymmdd int4 > key char(16) > value1 int4 > value2 int4 > > with the following sample data: > yyyymmdd key value1 value2 > 19981201 hello 32 16 > 19981201 bye 29 64 > 19981202 hello 16 20 > 19981202 bye 23 13 > > What I need is to select the greatest between value1 and value2, so the > answer would be: > yyyymmdd key value > 19981201 hello 32 > 19981201 bye 64 > 19981202 hello 20 > 19981202 bye 23 > > I can do this via ODBC using access by creating a column which is defined as > IF(value1>value2,value1,value2) but that doesn't work in psql. > > How can I make this work in psql? > > Thanks > Greg >