How could I SELECT the max of 2 different fields?

  • Thread starter Thread starter Aldred@office
  • Start date Start date
A

Aldred@office

Hi all,
I have a select statement like this:

Select Max(A_Date), Max(B_Date)
From blah blah blah...

How could I have my select statement to return the bigger (later) value of
these 2 selected fields?

Thanks.
 
Select Max(A_Date) AS MaxA,
Max(B_Date) AS MaxB
IIf(MaxB > MaxA, MaxB, MaxA) AS MostRecent
FROM Table1
GROUP BY ...

If you have multiple to choose from, you can use the MaxOfList() function
here:
http://allenbrowne.com/func-09.html

(Of course, that should not happen, since repeating fields like that
indicate you don't have a normalized schema.)
 
Thank you. It works. I just thought there would be something like
Greatest() in Oracle but I think there is not.
 
Back
Top