I am using mySQL
and CodeIgniter
. I have some floating point numbers in my database such as
SELECT * FROM table1 ORDER BY ABS(value - '$myvalue') LIMIT 1
Read this page http://dev.mysql.com/doc/refman/5.1/en/mathematical-functions.html#function_round
but your select would look like this
select value from table where ROUND(value) = $myvalue
select *
from table
order by abs(value - $myvalue)
limit 1
SELECT number, ABS( number - 2500 ) AS distance
FROM numbers
ORDER BY distance
LIMIT 6
Selecting closest values in MySQL
Try this:
SELECT *,abs((columnname -Yourvalue)) as near
FROM table
WHERE order by near limit 0,1