Question

I'm trying to do something like this:

SELECT MAX(
  ADDDATE(expirationdate, INTERVAL 1 YEAR),
  ADDDATE(now(), INTERVAL 1 YEAR)
)

That is, get "a year from now", or "a year from the expiration date stored in the table", whichever is greater (i'm renewing people's subscriptions).

This obviously doesn't work, since MAX() is for aggregation between rows, not for comparing 2 values. Is there a function that'll do this in MySQL? (i'd like to avoid doing an IF)

Was it helpful?

Solution

Licensed under: CC-BY-SA with attribution
Not affiliated with StackOverflow
scroll top