How could I SELECT the max of 2 different fields?

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.
 
A

Allen Browne

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.)
 
A

Aldred@office

Thank you. It works. I just thought there would be something like
Greatest() in Oracle but I think there is not.
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Top