Reputation: 481
I have this table:
How can I get the MAX date for each ID from each row?
Upvotes: 0
Views: 106
Reputation: 48177
Use Greatest
SELECT id, GREATEST (date1, date2, date3)
FROM YourTable
Note that GREATEST and LEAST are not in the SQL standard, but are a common extension. Some other databases make them return NULL if any argument is NULL, rather than only when all are NULL.
Upvotes: 1