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 ') AND `catalog_size_amount`.`amount` > 0 AND `catalog_size_amount`.`size` IN ('5' at line 1 [ SELECT `catalog`.`id`, IF(catalog_size_amount.amount > 0,1,0) as sortable FROM `catalog` JOIN `product_prices` ON (`catalog`.`id` = `product_prices`.`product_id`) JOIN `catalog_i18n` ON (`catalog`.`id` = `catalog_i18n`.`row_id`) LEFT JOIN `catalog_comments` AS `cc` ON (`cc`.`catalog_id` = `catalog`.`id` AND `cc`.`status` = 1) LEFT JOIN `catalog_categories` ON (`catalog_categories`.`catalog_id` = `catalog`.`id`) LEFT JOIN `catalog_tree` ON (`catalog_tree`.`id` = `catalog_categories`.`catalog_tree_id`) JOIN `product_ages` ON (`catalog`.`id` = `product_ages`.`product_id`) JOIN `catalog_size_amount` ON (`catalog_size_amount`.`catalog_id` = `catalog`.`id`) WHERE `catalog`.`status` = 1 AND `catalog_i18n`.`language` = 'ru' AND `product_prices`.`price_type` = '875e4eb9-364f-11ea-80cc-a4bf01075a5b' AND `catalog_categories`.`catalog_tree_id` IN ('42', '43', '55', '60', '61', '62', '65', '67', '68', '72', '73', '76', '77', '274', '275', '276', '277', '278', '281', '7', '44', '46', '47', '48', '49', '52', '58', '59', '69', '70', '78', '317', '318', '319', '320', '322', '323', '334', '336', '344', '45', '56', '64', '74', '311', '316', '325', '326', '327', '328', '329', '330', '331', '332', '333', '50', '53', '54', '57', '63', '71', '81', '215', '308', '309', '310', '313', '315', '321', '335', '342', '343') AND `product_ages`.`age_type` IN () AND `catalog_size_amount`.`amount` > 0 AND `catalog_size_amount`.`size` IN ('56') AND `catalog_size_amount`.`amount` <> 0 GROUP BY `catalog`.`id`, `product_prices`.`price`, `product_prices`.`price_old`, `product_prices`.`currency_id` ORDER BY CASE WHEN catalog.specifications LIKE "%vsesezon%" THEN 2 WHEN catalog.specifications LIKE "%demisezon%" THEN 1 WHEN catalog.specifications LIKE "%zima%" THEN 4 WHEN catalog.specifications LIKE "%leto%" THEN 3 WHEN catalog.specifications IS NULL THEN 4 END ASC, `catalog`.`new` DESC, `catalog`.`top` DESC, `catalog`.`sale` DESC, `catalog`.`id` DESC, `catalog`.`available` DESC ]