I have a table in a MySQL database from which I want to select the row with the closest timestamp to another given timestamp.
time is the timestamp column (an integer UNIX timestamp). I chose 1250710000 arbitrarily.
This is the query that I've come up with, and I'm wondering if there's a more efficient way to do it:
SELECT *, ABS(time - 1250710000) AS time_dist FROM table
ORDER BY time_dist ASC LIMIT 1
Is this the best way to do it?