You just need to enclose the SELECT in parentheses to indicate that they are subqueries:
SET cityLat = (SELECT cities.lat FROM cities WHERE cities.id = cityID);
Alternatively, you can use the MySQL SELECT ... INTO syntax. One of the advantages of this approach is that both cityLat and cityLng can be assigned from a single table access:
SELECT lat, lng INTO cityLat, cityLng FROM cities WHERE id = cityID;
However, the entire procedure can be replaced with one independent SELECT :
SELECT b.*, HAVERSINE(a.lat, a.lng, b.lat, b.lng) AS dist FROM cities AS a, cities AS b WHERE a.id = cityID ORDER BY dist LIMIT 10;
eggyal
source share