You have an error in your SQL syntax; check the manual that corresponds to your MySQL server version for the right syntax to use near '), 2) + POW(69.1 * ( - lang_city64.lng) * COS(lat / 57.3), 2)) AS distance ' at line 2 SELECT DISTINCT lang_city64.*, lang_country.name as cname, SQRT( POW(69.1 * (lang_city64.lat - ), 2) + POW(69.1 * ( - lang_city64.lng) * COS(lat / 57.3), 2)) AS distance FROM lang_country, lang_city64 Where lang_city64.id IN (89735,89725,89758,89759,89746,89740,89718,89719,89707,89741) and lang_country.country_id = lang_city64.country_id and lang_country.lang_id = 64 and lang_country.country_id = '132' and lang_city64.id <> 89721 group by lang_city64.short_name ORDER BY distance limit 0, 10