I'm making a sort of calendar of events app. There are 2 types of events shown on the users home page:
- nearby event - those with a schedule date within the next 3 days, or within the past 1 hour.
- normal event - those with either no schedule date, or a schedule date further than 3 days in the future.
This is the events table: id, user_id, content, occurs_at, created_at
Currently, I'm showing these events ordered by date created to show the newly added stuff first.
What I want is to show all nearby events first and have them ordered by schedule date, then show the normal events and have them ordered by date created. I think it makes for a better user experience, but I don't know how to go about it.
UPDATE
Ended up going with this query, which is a combination of a couple of answers.
ORDER BY COALESCE(occurs_at > :min_time AND occurs_at < :max_time, 0) DESC, occurs_at ASC, created_at DESC