Errormessage: SeLeCt a.id,a.name,a.city_id,a.lat,a.lon,a.address,a.postcode, ROUND(((ACOS(0.49737533874639 * SIN(a.lat * 0.017453292519943) + 0.86753545887584 * COS(a.lat * 0.017453292519943) * COS((-95.4672962 - 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 = 43022 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