I have a sql-query where I ask for some dates.
"SELECT DISTINCT date FROM table WHERE condition ORDER BY date");
The output is:
2007-04-08
2008-04-12
2008-09-27
2009-12-06
20开发者_开发百科10-01-31
2011-02-27
2011-04-15
Now I'm wondering whether it is possible to get the next date from the output above. Examples: 1. Today is 2008-12-12. The next date would be 2009-12-06. 2. Today is today/current_date (2011-02-22). The next date would be 2011-02-27.
Have you got an idea how to specify the query?
Thank you.
SELECT DISTINCT date FROM table WHERE dateColumn > CURDATE()
Order by dateColumn desc
If you want only the NEXT date, then you can use LIMIT
SELECT DISTINCT date FROM table WHERE dateColumn > CURDATE()
Order by dateColumn desc
LIMIT 1
精彩评论