You have an error in your SQL syntax; check the manual that corresponds to your MySQL server version for the right syntax to use near '?distance=0) AND ((`complex_params`.`name_entity` = 'region' AND `complex_params' at line 1 [ SELECT `complex`.`id`, `complex`.`price`, `complex`.`price_one`, `complex`.`price_max`, `complex`.`metering_min`, `complex`.`metering_max`, `complex`.`status_construction`, `complex`.`number_flats`, `complex`.`reliable`, `complex`.`maps`, `complex`.`alias`, `complex`.`image`, `complex`.`image_logo`, `complex`.`image_layout`, `complex`.`top_price`, `complex`.`specifications`, `complex`.`specifications_param`, `complex`.`params_value`, `complex`.`check_maps`, `complex`.`premium`, `complex`.`individual_credit`, `complex`.`advertisement`, `complex`.`share_percentage`, `complex`.`stock_link`, `complex`.`show_ads`, `complex`.`promotion`, `complex`.`builder_alias`, `complex_i18n`.`address`, `complex_i18n`.`name`, `complex_i18n`.`stock_text`, COUNT(DISTINCT complex_params.name_entity) AS cList FROM `complex` JOIN `complex_i18n` ON (`complex`.`id` = `complex_i18n`.`row_id`) JOIN `complex_params` ON (`complex_params`.`complex_alias` = `complex`.`alias`) WHERE `complex_i18n`.`language` = 'ua' AND `complex`.`status` = 1 AND (`complex`.`distance` BETWEEN 0 and 10?distance=0) AND ((`complex_params`.`name_entity` = 'region' AND `complex_params`.`alias_value` IN ('vinnitskaja'))) GROUP BY `complex`.`id` HAVING `cList` >= 1 ORDER BY `complex`.`sort` ASC ]