Errormessage: SeLeCt a.id,a.name,a.city_id,a.lat,a.lon,a.address,a.postcode, ROUND(((ACOS(-0.61291274372387 * SIN(a.lat * 0.017453292519943) + 0.79015059867146 * COS(a.lat * 0.017453292519943) * COS((144.9426392 - 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 = 13188 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