Mask Mask - 5 months ago 24
MySQL Question

How to get the max of two values in MySQL?

I tried but failed:

mysql> select max(1,0);



ERROR 1064 (42000): You have an error in your SQL syntax; check the manual
that corresponds to your MySQL server version for the right syntax to use
near '0)' at line 1

Answer

Use GREATEST()

E.g.:

SELECT GREATEST(2,1);