SELECT GROUP_CONCAT(DISTINCT bh.bh_opentime) AS open_times, GROUP_CONCAT(DISTINCT bh.bh_closetime) AS close_times, GROUP_CONCAT(DISTINCT sbh.special_bh_opentime) AS special_opens, GROUP_CONCAT(DISTINCT sbh.special_bh_closetime) AS special_closes, fn_distance(52.35, 4.91667, o.`organisation_lat`, o.`organisation_long`) as distance, o.*, c.`city_name`, c.`city_name_safe`, main_branche.`tag_name` as main_branche , main_branche.`tag_name` AS branche_name, b1.`branche_name_safe` as main_branche_safe, b2.`branche_id` as sub_parent, b2.`branche_name_safe` as main_branche_safe2, b3.`branche_id` as main_parent, b3.`branche_name_safe` as main_branche_safe3, parent.`organisation_image` as parent_logo, parent.`organisation_header_image` as parent_header FROM `organisations` o INNER JOIN `cities` c ON c.`city_id` = o.`organisation_city` INNER JOIN `organisation_branche` ob ON ob.`organisation_id` = o.`organisation_id` LEFT JOIN `branches` b1 ON ob.`branche_id` = b1.`branche_id` LEFT JOIN `branches` b2 ON b1.`branche_parent` = b2.`branche_id` LEFT JOIN `branches` b3 ON b2.`branche_parent` = b3.`branche_id` INNER JOIN `tags_taxonomies` main_branche_tt ON main_branche_tt.`object_id` = o.`branche_id` AND main_branche_tt.`taxonomy` = 'branche_tag' INNER JOIN `tags` main_branche ON main_branche.`tag_id` = main_branche_tt.`tag_id` LEFT JOIN `business_hours` bh ON bh.organisation_id = o.organisation_id AND bh.`bh_day` = 2 LEFT JOIN `special_business_hours` sbh ON sbh.organisation_id = o.organisation_id AND ((('2024-05-15' BETWEEN sbh.`special_bh_from_date` AND sbh.`special_bh_to_date`) AND sbh.`special_bh_days` = '') OR (('2024-05-15' BETWEEN sbh.`special_bh_from_date` AND sbh.`special_bh_to_date`) AND sbh.`special_bh_days` LIKE '%2%')) LEFT JOIN `organisations` parent ON o.`organisation_parent` = parent.`organisation_id` WHERE o.`organisation_parent` = AND (o.`organisation_show` = 1 OR o.`organisation_show` = 4) GROUP BY o.`organisation_id` ORDER BY fn_distance(52.35, 4.91667, o.`organisation_lat`, o.`organisation_long`) ASC : 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 (o.`organisation_show` = 1 OR o.`organisation_show` = 4) GROUP BY o.`organis' at line 11