Why can't I do this?
SELECT MAX(1, 2, 3, 4);
I'm just learning SQL and this is for learning purposes. I expect the result to be 4, but I get an error
Error Code: 1064. 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 ', 2, 3, 4)' at line 1
CodePudding user response:
You're not looking for MAX here, but GREATEST:
SELECT GREATEST(1, 2, 3, 4);
CodePudding user response:
I finally did it with the MAX function. I know it's ugly and probably no one will use it this way, but I wanted to do it with MAX Here's the code
SELECT MAX(`values`) FROM(
SELECT 1 AS `values`
UNION
SELECT 2
UNION
SELECT 3
UNION
SELECT 4
) a