have a couple of dates in a few fields, basically
SELECT MAX(MAX(DATE_A),MAX(DATE_B)) from table
DATE_A and DATE_B are dates, i basically want the maximum of the latest date of either date A or date B
I searched online but max as a keyword makes it very hard to find what im looking for
This first uses
GREATEST(date_a,date_b)to reduce these two columns into just one, containing the greatest value for each row.The
MAXthen selects the one maximum value over all of these.It also prevents repeated evaluation of
MAXto make things a littler more efficient.GREATESTdocumentation,MAXdocumentation.Note that
GREATESToperates across columns, whereasMAXoperates across rows, which is why you need to use them both to get the single maximum value across both rows and columns.