JT.
JT.

Reputation: 351

min and max value for a row, not column

In my mysql table on the same row i have a persons name, value1, value2, value3, value4, value5. I want to get the lowest value from values 1-5 and put it in column lowestvalue.

I know how to get minimum and maximum values from a chosen column, as stated in mysql documentation 3.6.1, but i dont know how to get minimum and maximum values from a chosen row. I cant find that in mysql documentation.

Could some one tell me or point me in the right direction. Cheers

Upvotes: 0

Views: 281

Answers (2)

Denis Shvydenko
Denis Shvydenko

Reputation: 86

Create another table (name, value), link it with first table by name and use standart min/max functions

Upvotes: 1

Niet the Dark Absol
Niet the Dark Absol

Reputation: 324840

SELECT GREATEST(`value1`, `value2`, `value3`, `value4`, `value5`) as `highest`
FROM `tablename` WHERE .....

Upvotes: 2

Related Questions