Oracle Greatest Function

I came across an issue the other day at work that I thought I could not solve without PL/SQL. I researched because I wanted to get the result using a SQL statement. My issue was that I needed to find the max value between two columns in Oracle. Here is an example table

FEAT_ID FEAT1 LOW1 HIGH1 FEAT2 LOW2 HIGH2
133977 2014 120 120 2825 86 86
133977 2013 4 4 2826 12 12

I wanted to find the greatest value between HIGH1 and HIGH2. I found this nice function.


SELECT GREATEST(HIGH1,HIGH2) FROM SPLICE_CONNECT WHERE FEAT_ID = 133977 AND FEAT1 = 2014 AND HIGH1 = 120;

This of course returns 120 since 120 > 86.

 

You can learn more about the greatest function here