MySQL - Searching negative longitude values with BETWEEN

只谈情不闲聊 提交于 2019-12-04 03:27:59

You can also use the greatest() and least() functions, so you don't have to worry about the parameters. For example:

SELECT * FROM table
WHERE latitude BETWEEN least(@lat1, @lat2) AND greatest(@lat1, @lat2)
AND  longitude BETWEEN least(@lon1, @lon2) AND greatest(@lon1, @lon2)

between expects the format to be somefield BETWEEN lowervalue AND highervalue. Your negative longitudes have the higher/lower values switched. It should be

AND longitude BETWEEN -97.083997 AND -97.077303

negative 97.08 is actually lower than negative 97.07

Do check how negative numbers appear on a number line. :)

SELECT *
FROM `table` 
WHERE `latitude` BETWEEN 47.926930 AND 47.929806 
  AND `longitude` BETWEEN -97.083997 AND -97.077303 
易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!