I have MySQL query I can't solve and couldn't find solution by googling. I have table something like this:
recnr event date
1 event1 today-3
2 event2 today-2
3 event3 today
4 event4 today
5 event5 today+3
6 event6 today+7
I have to create query which will select 3 most recent events starting with today. I've tried with:
SELECT event FROM table
WHERE (date <= CURDATE()) recnr LIMIT 3;
but it selects first three events in the table. How to tell it to start with today and go backwards and not to start with first and go forward?
Use an order by statement?
SELECT event FROM table WHERE (date <= CURDATE()) ORDER BY date DESC LIMIT 3;
You need an order by
clause in your query
Reference - order by
SELECT event FROM table WHERE (date <= CURDATE()) ORDER BY date DESC LIMIT 3 ;