Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Is there a 'greatest' function in db2?

Tags:

sql

db2

I found in MYSQL and apparently other database engines that there is a "greatest" function that can be used like: greatest(1, 2, 3, 4), and it would return 4. I need this, but I am using IBM's DB2. Does anybody know of such an equivalent function, even if it only accepts 2 parameters?

I found somewhere that MAX should do it, but it doesn't work... it only works on selecting the MAX of a column.

If there is no such function, does anybody have an idea what a stored procedure to do this might look like? (I have no stored procedure experience, so I have no clue what DB2 would be capable of).

like image 539
Mike Stone Avatar asked Jan 20 '26 02:01

Mike Stone


1 Answers

Why does MAX not work for you?

select max(1,2,8,3,1,7) from sysibm.sysdummy1

gives me

    1
    ---------------
                 8

      1 record(s) selected.
like image 92
Dave Avatar answered Jan 22 '26 17:01

Dave