Friends, there are 2 tables (product and discounts) you need to choose MIN and MAX prices, considering that the product can also have a discount. I do something like this

select IF(s.status, s.specials_new_products_price, p.products_price) AS MAX(products_price), IF(s.status, s.specials_new_products_price, p.products_price) AS MIN(products_price), c.parent_id, c.categories_id from ".TABLE_PRODUCTS_TO_CATEGORIES." p2c, ".TABLE_PRODUCTS." p LEFT JOIN " . TABLE_SPECIALS . " s ON (p.products_id = s.products_id).... 

But something is not right. No IF () used to just request

 select MAX(p.products_price), MIN(p.products_price), c.parent_id, c.categories_id from ".TABLE_PRODUCTS_TO_CATEGORIES." p2c, ".TABLE_PRODUCTS." p, ".TABLE_CATEGORIES." c where p.products_status = '1'.... 

and lower values

 $maxpr = $res_maxpr['MAX(p.products_price)']; $minpr = $res_maxpr['MIN(p.products_price)']; 

    1 answer 1

    In order to get the maximum / minimum value from the data series, you need to place the IF function inside the MAX or MIN function:

     SELECT MIN(IF(s.status, s.specials_new_products_price, p.products_price)) AS min_price ... 

    In this case, if the FROM and WHERE query section were compiled correctly, they can not be changed.