In the following table (all columns are integer)
[id, value, best_value]
For this id and value, I want it to update the row by setting the best_value column to max (newvalue, best_value). I connected to the documentation, but I do not see the function for this.
thanks
You want GREATEST(x,y) . For example, if the new value is 530:
GREATEST(x,y)
UPDATE my_table SET best_value = GREATEST(530,best_value) WHERE id=123
You do not need such a function,
UPDATE my_table SET best_value = new_value WHERE id=123 AND best_value < new_value
will accomplish this task as well as AlienWebguy's answer :)