12 messages in com.mysql.lists.mysqlRe: Select MAX(column1,column2)
FromSent OnAttachments
Scott Klarenbach26 May 2005 13:25 
Keith Ivey27 May 2005 12:02 
Jay Blanchard27 May 2005 12:06 
SGr...@unimin.com27 May 2005 12:11 
Scott Klarenbach27 May 2005 13:47 
mfat...@free.fr27 May 2005 14:44 
Keith Ivey27 May 2005 15:03 
mfat...@free.fr27 May 2005 15:20 
mfat...@free.fr27 May 2005 15:22 
Scott Klarenbach27 May 2005 15:36 
Scott Klarenbach01 Jun 2005 13:57 
mfat...@free.fr01 Jun 2005 14:23 
Subject:Re: Select MAX(column1,column2)
From:Scott Klarenbach (doyo@gmail.com)
Date:05/27/2005 01:47:54 PM
List:com.mysql.lists.mysql

Thanks Keith. It didn't quite work as expected, but it helps me a lot none the less.

The Documentation says it returns the max value, so select greatest(1, 2, 3, 4) will return 4.

But, across multiple column names, it returns all the values in one column, not just the greatest one...so

select greatest(fieldone, fieldtwo, fieldthree, fieldfour) from table returns

10 12 14 29 6 3 444

etc...from all 4 of those fields.

So, by going Select MAX(GREATEST(fieldone, fieldtwo, fieldthree)) I can accomplish exactly what I've been banging my head against a wall for...thanks.

On 5/27/05, Keith Ivey <kei@smokefreedc.org> wrote:

Scott Klarenbach wrote:

Can I select the maximum value across multiple columns?

You want the GREATEST() function:

http://dev.mysql.com/doc/mysql/en/comparison-operators.html