mysql - SQL: Select the next datetime in the future from one of two columns -
i have table similar this:
+---------------------+---------------------+ |                |                  | +---------------------+---------------------+ | 2014-07-01 01:00:00 | null                | +---------------------+---------------------+ | 2015-08-01 02:00:00 | 2015-10-01 02:00:00 | +---------------------+---------------------+ | 2015-09-01 03:00:00 | 2015-10-01 03:00:00 | +---------------------+---------------------+   and need know next datetime in future, should be: 2015-08-01 02:00:00
i'm looking "correct" answer, ideally without subqueries or joins.
edit:
assuming from before to each row, don't need least:
select min(if(`from` > now(), `from`, `to`)) `yourtable` `from` > now()    or `to` > now();   this works because 1 of from or to have > now() or where eliminates row. in procedural pseudo code like
x = ("from" "from" > now) ,     ("to" "from" < , "to" > now) min(x)      
Comments
Post a Comment