Hi
I have a table with a column event_time
. How can I select two rows right before NOW() and the next one after NOW(), ordered by event_time
?
Is is possible with a single query?
Hi
I have a table with a column event_time
. How can I select two rows right before NOW() and the next one after NOW(), ordered by event_time
?
Is is possible with a single query?
How about something like
SELECT *
FROM (
SELECT *
FROM TABLE
WHERE event_time < NOW()
ORDER BY event_time DESC
LIMIT 2
) First2
UNION ALL
SELECT *
FROM (
SELECT *
FROM TABLE
WHERE event_time > NOW()
ORDER BY event_time ASC
LIMIT 1
) Next1
ORDER BY event_time