Hi,

Try like this....

(SELECT * FROM (SELECT * FROM tab_name ORDER BY latitute ASC, longitude ASC) a
WHERE a.latitude<=givenvalue AND a.longitude<=givenvalue
LIMIT 0,5)
UNION
(SELECT * FROM (SELECT * FROM tab_name ORDER BY latitute ASC, longitude ASC) b
WHERE b.latitude>givenvalue AND b.longitude>givenvalue
LIMIT 0,5)
;

Thanks,
ViSolveDB Team

----- Original Message ----- From: "M5" <[EMAIL PROTECTED]>
To: <mysql@lists.mysql.com>
Sent: Saturday, February 03, 2007 7:30 AM
Subject: How to SELECT rows closest to value


Simply put, I have a table of ~800,000 records containing, among other things, latitude and longitude values. Given a lat/lng pair, I would like to SELECT from this table the 10 rows containing latitude/ longitude values closest to the given lat/lng pair. Possible?

...Rene


--
MySQL General Mailing List
For list archives: http://lists.mysql.com/mysql
To unsubscribe: http://lists.mysql.com/[EMAIL PROTECTED]



--
No virus found in this incoming message.
Checked by AVG Free Edition.
Version: 7.1.411 / Virus Database: 268.17.19/663 - Release Date: 2/1/2007




--
MySQL General Mailing List
For list archives: http://lists.mysql.com/mysql
To unsubscribe:    http://lists.mysql.com/[EMAIL PROTECTED]

Reply via email to