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 ') ORDER BY CASE WHEN users.vip = 1 THEN 0 WHEN users.partner = 1 THEN -1 END ...' at line 1 [ SELECT `catalog`.*, `catalog_i18n`.`name`, LTRIM(catalog_i18n.name) AS `name`, `resorts_i18n`.`name` AS `resort_type`, `catalog_tree_i18n`.`name` AS `type`, `users`.`vip`, `users`.`partner`, `catalog_comments`.`comments` FROM `catalog` LEFT JOIN `catalog_i18n` ON (`catalog_i18n`.`row_id` = `catalog`.`id`) LEFT JOIN `users` ON (`catalog`.`user_id` = `users`.`id`) JOIN `catalog_tree` ON (`catalog`.`parent_id` = `catalog_tree`.`id`) JOIN `catalog_tree_i18n` ON (`catalog_tree`.`id` = `catalog_tree_i18n`.`row_id`) LEFT JOIN `resorts` ON (`catalog`.`resort_id` = `resorts`.`id`) LEFT JOIN `resorts_i18n` ON (`resorts_i18n`.`row_id` = `resorts`.`id`) LEFT OUTER JOIN (SELECT `catalog_id`, COUNT(catalog_comments.catalog_id) AS `comments` FROM `catalog_comments` GROUP BY `catalog_id`) AS `catalog_comments` ON (`catalog_comments`.`catalog_id` = `catalog`.`id`) LEFT OUTER JOIN (SELECT `pension_id`, AVG(rating) AS `reviews` FROM `rating` GROUP BY `pension_id`) AS `rating` ON (`rating`.`pension_id` = `catalog`.`id`) WHERE `catalog_i18n`.`language` = 'ru' AND `catalog_tree_i18n`.`language` = 'ru' AND `resorts_i18n`.`language` = 'ru' AND `catalog_i18n`.`language` = 'ru' AND `catalog`.`status` = 1 AND `catalog`.`resort_id` IN () ORDER BY CASE WHEN users.vip = 1 THEN 0 WHEN users.partner = 1 THEN -1 END DESC, `catalog`.`sort` ASC, `catalog`.`id` ASC LIMIT 24 OFFSET 0 ]