Skip to content
Advertisement

Finding max value of multiple columns in Sql

How can I find maximum value on multiple columns. This is what I have so far.

This code is giving me the error: Incorrect syntax near ‘maxval’.

Advertisement

Answer

Are you simply looking for GREATEST?

However GREATEST Returns NULL when a value is NULL, so you might want to care about this, too. For instance:

EDIT: In case GREATEST is not available in your dbms you can use a case expression.

EDIT: To get your own statement syntactically correct, do:

User contributions licensed under: CC BY-SA
8 People found this is helpful
Advertisement