Reputation: 27
I have a MYSQL Table with multiple columns:
col1 | col2 | col3 | col4 | col5 | col6 | min_all_col |
25 | 27 | 35 | 21 | 37 | 34 | |
I need to know how I can update the column (min_all_cols), with the minimum value of all 6 columns e.g 21 I have tried several UPDATE statements but just seem to confuse myself.
Can anyone help me? Regards
Upvotes: 1
Views: 63
Reputation: 21657
Use LEAST:
LEAST(value1,value2,...)
With two or more arguments, returns the smallest (minimum-valued) argument.
UPDATE tableName
SET min_all_col = LEAST(col1,col2,col3,col4,col5,col6);
Upvotes: 1