I want to compare two dates from two columns and get the greatest and then compare against a date value.The two column can hold NULL values too.For example I want the below OUTP
You might try the following:
SELECT cola, colb, COALESCE( GREATEST( cola, colb ), cola, colb ) AS output FROM yourtable;
The reason for COALESCE() is that GREATEST() returns NULL if either of the parameters is NULL.
COALESCE()
GREATEST()
NULL