Sql value is closest or equal to a certain value in a field
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?
select *
FROM table
where abs($postid-POSTIDS) = (select min( abs($postid-POSTIDS))
from table )
精彩评论