ERROR: select distinct p2c.products_id as products_id , IF(s.status, s.specials_new_products_price, if(min(products_prices.products_sale_price),min(products_prices.products_sale_price),min(products_prices.products_price) )) as final_price from products_to_categories p2c LEFT JOIN products_description on products_description.products_id=p2c.products_id LEFT JOIN `categories` c on p2c.categories_id=c.categories_id LEFT JOIN products_to_flags p2f on p2c.products_id=p2f.products_id LEFT JOIN `flags` on p2f.flag_id=flags.flag_id left join products p on p.products_id=p2c.products_id left join products_to_categories p2c2 on p2c.products_id=p2c2.products_id left join categories c2 on p2c2.categories_id=c2.categories_id left join specials s on p2c.products_id = s.products_id left join products_prices on products_prices.products_id=p2c.products_id where (c.categories_id=882 or c.parent_id=882) and (c2.categories_id=882 or c2.parent_id=882) and p.products_status = 1 and p.discontinued=0 group by p2c.products_id order by final_price DESC