Errormessage: SeLeCt a.id,a.name,a.city_id,a.lat,a.lon,a.address,a.postcode, ROUND(((ACOS(0.56081919378259 * SIN(a.lat * 0.017453292519943) + 0.82793830197971 * COS(a.lat * 0.017453292519943) * COS((-118.3163686 - a.lon) * 0.017453292519943)) * 180 / 3.1415926535898) * 69),5) AS distance, b.name city_name, d.name parent_name, e.code area_code, b.subdomain FROM comclass c JOIN companies a on a.id = c.comp_id LEFT JOIN geo_Locality b on a.city_id = b.id LEFT JOIN geo_Locality d on b.parent = d.id JOIN geo_AdministrativeArea e on e.id = b.aa_id WHERE c.city_id = 3344 AND c.cat_id = AND a.approved > -1 AND a.lat IS NOT NULL ORDER by distance LIMIT 7 You have an error in your SQL syntax; check the manual that corresponds to your MariaDB server version for the right syntax to use near 'AND a.approved > -1 AND a.lat IS NOT NULL ORDER by distance LIMIT 7' at line 9