^ "SELECT p.id_product FROM (SELECT p.id_product, p.id_manufacturer, SUM(sa.quantity) as quantity, p.condition, p.weight, p.price, psales.quantity as sales, p.on_sale, p.date_add, cp.position FROM ps_product p LEFT JOIN ps_product_attribute pa ON (p.id_product = pa.id_product) LEFT JOIN ps_product_attribute_combination pac ON (pa.id_product_attribute = pac.id_product_attribute) LEFT JOIN ps_stock_available sa ON (p.id_product = sa.id_product AND IFNULL(pac.id_product_attribute, 0) = sa.id_product_attribute AND sa.id_shop_group = 1 AND sa.id_shop = 0 ) LEFT JOIN ps_product_sale psales ON (psales.id_product = p.id_product) INNER JOIN ps_category_product cp ON (p.id_product = cp.id_product) INNER JOIN ps_product_shop ps ON (p.id_product = ps.id_product AND ps.id_shop = 1 AND ps.active = TRUE) INNER JOIN ps_category c ON (cp.id_category = c.id_category AND c.active=1) LEFT JOIN ps_category_group cg ON (cg.id_category = c.id_category) LEFT JOIN ps_feature_product fp_1 ON (p.id_product = fp_1.id_product) LEFT JOIN ps_feature_product fp_2 ON (p.id_product = fp_2.id_product) WHERE ((sa.out_of_stock IN (1, 2)) OR (sa.quantity>0)) AND ((fp_1.id_feature_value=68)) AND ((fp_2.id_feature_value IN (24, 31, 97))) AND ps.id_shop='1' AND ps.visibility IN ('both', 'catalog') AND cg.id_group='1' AND p.date_add>'2011-11-19 00:00:00' AND c.nleft>=3 AND c.nright<=12 GROUP BY p.id_product ORDER BY (sa.quantity > 0) desc) p INNER JOIN ps_category_product cp ON (p.id_product = cp.id_product) GROUP BY p.id_product ORDER BY (sa.quantity > 0) desc, p.position ASC"
123