How to find the maximum of two explicit values in MySQL? Something like MAXIMUM(1, @foo).
There are group functions like MAX, MIN, AVG, etc that take column name as an argument and work with result sets. Is it possible to convert two explicit values to a result set and use those functions? Some other ways?
P.S.: I need a max function for one of my stored procedures.
Use the GREATEST function:
…will return whichever value is larger – if 1 is larger than the value in @foo, you’ll get 1. Otherwise, you’ll get whatever value is in @foo. Also, it’s not an aggregate function.
The alternative would be to use a CASE statement:
…because CASE is ANSI standard – that will work on Oracle, MySQL, SQL Server, Postgres…