Error in the consult.. 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 fran_status.type != "off" AND location.live_status = "live" GROUP BY t' at line 22SELECT DISTINCT territory.* ,COUNT(DISTINCT AS num_locations, GROUP_CONCAT(DISTINCT connect_locations.location_id) AS location_ids, GROUP_CONCAT(DISTINCT AS status_id, user.avatar AS user_avatar, CONCAT(user.first_name, " ", user.last_name) AS user_name FROM oak_franchise_territories AS territory LEFT JOIN oak_franchise_location_territories AS connect_locations ON (connect_locations.territory_id = ) LEFT JOIN oak_franchise_locations AS location ON (connect_locations.location_id = LEFT JOIN oak_franchise_statuses AS fran_status ON (FIND_IN_SET(fran_status.alias, location.status)) LEFT JOIN oak_users AS user ON (territory.modified_by = WHERE 1 AND connect_locations.location_id = AND fran_status.type != "off" AND location.live_status = "live" GROUP BY ORDER BY;