How can I compare values with SQL?

If actual performance exceeds the guaranteed minimum, payment should be calculated on the basis of that minimum.

Yet, can I compare those two values, directly in my query?

Sure! Check out examples below:

In a nutshell, greatest() and least() make very neat SQL functions as they:

  • can compare more than 2 values
  • have the same syntax in most DBs (excepton being SQL Server where they do not have direct equvalents)

Happy SQL-ing!