Does anyone know a good way to compare several columns and return the largest value, somewhat like what MAX does for a single column?
Return largest value from multiple columns
Collapse
X
-
Depends on how many columns you are comparing against. You could try the IF function. Have a look at thisOriginally posted by akseloDoes anyone know a good way to compare several columns and return the largest value, somewhat like what MAX does for a single column?
[CODE=mysql]select IF(max(co1a) > max(colb), max(cola), max(colb))[/CODE] -
Thank you for the quick response. I have six fields with different square footage information for land use types (residential, commercial, office, etc), and hope to return the largest value for the parcel in question, and while I considered the if statement, this method seems cumbersome as I would need to test each field against all others and end up with 6 different nested if statements. Could one define an array of six columns and return the largest?Originally posted by r035198xDepends on how many columns you are comparing against. You could try the IF function. Have a look at this
[CODE=mysql]select IF(max(co1a) > max(colb), max(cola), max(colb))[/CODE]Comment
-
you can use the following:
select greatest(100,67 ,876,76,234,100 98) from dual;
can be used in any sql statement , just list the relevant comments inside the greatest () functionComment
Comment