I am sure this is a common task although all of the examples I have looked at dont help me solve this issue.
I have 2 tables:
eventsscheduleswith foreign key to events. Withschedule_datetime_fromandschedule_datetime_until
Q. When selecting all of the events, how would I also fetch/join the first closest schedule based on todays date? E.g only return the most relevant schedule.
NOTE: There maybe more than one schedule for each event. The schedule may also be in the past.
E.g e.schedule_datetime_from >= NOW() OR schedule_datetime_until > NOW() would return only the future schedules, but how do I also return schedules in the past. Or do I need to use a ORDER BY + LIMIT 1 to achieve this?
1 Answer