I would like to know how to get the min numeric value from a single row, for example:
My table:
|col a|col b|col c|some other col|some other col|
-------------------------------------------------
| 13 | 2 | 5 | 0 | 0 |
The question is: how do I get the min value from col a, col b and col c (I want to ignore the other columns.
I have try this: SELECT MIN(col a, col b, col c) from table WHERE id=0
But surly this doesn't work.
Any help will be appreciated.
The correct function in MySQL is
least()
:Very important: This assumes that all values are non-NULL. If you have
NULL
values, thenleast()
returnsNULL
.If you need to take this into account, you can use
coalesce()
. . . One method is to use a highest value:Or, use a
coalesce()
on the values in the columns: