Q:

Get 5 rows from table

I want to fetch 5 rows from table whose "lat" value is nearest to 30. I am developing Google MAP app, where i need the 5 nearest location from Data Base.
My table looks like that,

A:

MySQL provides a Math function that turns negative numbers into absolute values. By using that, you can get the five closest locations whether their lat is slightly lower or higher than 30:
ORDER BY ABS(lat - 30) ASC LIMIT 5

The ASC is optional as it is the default sorting order in all DBMS (thanks Gordon).

