SQL – MAX/Greatest()

SQL – MAX/Greatest()

Hey all, this is the first big conversion I ran into with MSSQL and MySQL. In Excel, you can use the MAX() function to find the highest value in a row.

=MAX(A1, B1, C1)

When this is converted into MSSQL, we need to use an additional function in order to find this result.

SET MaxValue = dbo.MaxValue( [Field1], [Field2], [Field3])

In this example, the function MaxValue takes the fields into an array and will then determine which is the highest value.

In MySQL, the same can be achieved with the Greatest() function.

SET MaxValue = GREATEST([Field1], [Field2], [Field3])

Thankfully there is no need for any additional code beyond this.

2 thoughts on “SQL – MAX/Greatest()

  • Excellent article. Keep posting such kind of info onn your
    blog. Im really impressed byy it.
    Hello there, You’ve done an incrediblle job. I will certainly
    digg it and in my opinion suggest to my friends. I am
    sure they’ll be benefited from this web site.

  • Comments are closed.