Reputation: 4099
Consider the following table (dates
):
_date
------------
2011-03-14
2011-03-15
2011-03-16
2011-03-19
2011-03-20
2011-03-22
2011-03-23
With what query can I return the first date in dates
following any given date? Pseudo:
SELECT <<nextdate>> FROM dates WHERE _date = '2011-03-14'
This query would have to return 2011-03-15
, since it is the first date in dates
after 2011-03-15
. But when querying the following:
SELECT <<nextdate>> FROM dates WHERE _date = '2011-03-16'
Then the query should return 2011-03-19
, as it is the first date in dates
after 2011-03-16
.
Who can help me our here? Your help is greatly appreciated.
Upvotes: 1
Views: 77
Reputation: 254886
SELECT _date
FROM dates
WHERE _date > '2011-03-14'
ORDER BY _date
LIMIT 1
Upvotes: 6