Errormessage: SeLeCt a.id,a.name,a.city_id,a.lat,a.lon,a.address,a.postcode, ROUND(((ACOS(-0.55675508851707 * SIN(a.lat * 0.017453292519943) + 0.83067669487614 * COS(a.lat * 0.017453292519943) * COS((151.1251488 - a.lon) * 0.017453292519943)) * 180 / 3.1415926535898) * 111.044736),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 = 4604 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