Search request max. Three columns per row

I have three dates in the table, for each record I need to find a maximum of three columns and I need to ignore incase if the column is zero, could you help with this?

I am using oracle version 10g.

Table-1
---------
SL NO date1 date2 date3 age
+4
source share
3 answers

Since it GREATESTwill return NULLif any of the values ​​you pass is equal NULL, you need a combination of GREATESTand COALESCE:

SELECT GREATEST(
    COALESCE(date1, date2, date3)
,   COALESCE(date2, date1, date3)
,   COALESCE(date3, date1, date2)
)
FROM my_test_table
+4
source

You can use a function GREATESTthat returns the largest of the given n arguments:

SELECT GREATEST(date1, date2, date3)
FROM   table1
+1
source

( ), GREATEST:

sslect
...,
GREATEST (date1,date2,date3)
from...
0

All Articles