How to get the max of two values in MySQL?
Use GREATEST()
E.g.:
SELECT GREATEST(2,1);
Note: Whenever if any single value contains null at that time this function always returns null (Thanks to user @sanghavi7)
You can use GREATEST function with not nullable fields.If one of this values (or both) can be NULL, don't use it (result can be NULL).
select if( fieldA is NULL, if(fieldB is NULL, NULL, fieldB), /* second NULL is default value */ if(fieldB is NULL, field A, GREATEST(fieldA, fieldB)) ) as maxValue
You can change NULL to your preferred default value (if both values is NULL).