SELECT a.*, (a.price - (a.price * a.discount / 100)) discount_price FROM ( SELECT P.*, (SELECT value FROM product_params PP WHERE PP.product_id = P.product_id AND PP.param_type = 21) price, (SELECT value FROM product_params PP WHERE PP.product_id = P.product_id AND PP.param_type = 24) discount FROM products P WHERE product_id IN (SELECT product_id FROM product_params WHERE param_type = 24) ) a ORDER BY discount_price DESC Got error 28 from storage engine