Suppose I have a timestamp as a parameter I call it “C”.
And in the database I have a table “TABLE” which contains 2 fields. Timestamp “A”, Timestamp “B”.
I want to fetch rows from “TABLE” which is sorted by “A” that is nearest to “C” and hasn’t passed “B” yet. How do I do that?
I know how to query the condition now() <= “B”. But I can’t do the sorting in a single query.
What’s the most efficient way of doing this?
As long as you didn’t say what database server you use, here is a tip:
This way you’ll get the events that has
timestamp_bthat hasn’t passed yet and ordered by the “closeness” to timestamp_a