SELECT products.products_id, products_sizes.size_id, products_sizes.size_title, product_price.price, product_price.qty, product_price.qty_to, product_price.corporate_id, product_price.user_type_id, products.predefined_product_type, products.price_defining_method, products.enable_sheet_calculation, product_price.color_page_price, products.enable_color_pages, product_price.extra_page_price, products.kit_type_id, product_price.product_price_id, vendor_price.vendor_price,vendor_price.vendor_color_price,vendor_price.vendor_price_extra_page, product_price.price AS products_wholesale_price, IF(product_price_markup.product_price_id IS NOT NULL, product_price_markup.store_price, (product_price.price + ((product_price.price * 0)/100))) as price,product_price.color_page_price AS products_wholesale_color_price, IF(product_price_markup.product_price_id IS NOT NULL, product_price_markup.color_store_price, (product_price.color_page_price + ((product_price.color_page_price * 0)/100))) as color_page_price FROM products LEFT JOIN `product_price` ON `product_price`.`products_id` = `products`.`products_id` AND `product_price`.`visible` = '1' AND (`product_price`.`user_type_id` = '1') LEFT JOIN vendor_price ON vendor_price.price_id = product_price.product_price_id AND vendor_price.price_type='P' LEFT JOIN product_price_markup ON product_price.product_price_id = product_price_markup.product_price_id AND product_price_markup.store_id = 138 RIGHT JOIN `products_sizes` ON `products_sizes`.`products_id` = `products`.`products_id` AND `products_sizes`.`size_id` = `product_price`.`size_id` AND `products_sizes`.`site_language_id` = 1 AND `products_sizes`.`visible`='1' LEFT JOIN store_products ON store_products.products_id = products.products_id WHERE `products`.`products_id` IN (6597) AND IF ( `products`.`price_defining_method` IN ('1', '2', '3'), `product_price`.`qty_to` != 0, 1) AND products.predefined_product_type IN ('0', '1') AND store_products.store_id = 138 GROUP BY products_sizes.size_id, product_price.qty, product_price.qty_to, product_price.corporate_id, product_price.user_type_id ORDER BY `products_sizes`.`sort_order` ASC, `product_price`.`corporate_id` DESC, `products`.`sort_order` ASC, `product_price`.`products_id` ASC, `product_price`.`qty` ASC