Reputation: 5831
I have a mysql table with a field called POSTIDS POSTIDS values: 1,2,6,7,15,24,25,63,78,98,120
I have a variable called $postid = '21'
SELECT * FROM table WHERE POSTIDS "is closest" to $postid (in this case 21)
How can i do this?
Upvotes: 0
Views: 336
Reputation: 16677
select *
FROM table
where abs($postid-POSTIDS) = (select min( abs($postid-POSTIDS))
from table )
Upvotes: 1