SELECT
cscart_product_prices.product_id,
COALESCE(
cscart_master_products_storefront_min_price.price,
MIN(
IF(
cscart_product_prices.percentage_discount = 0,
cscart_product_prices.price,
cscart_product_prices.price - (
cscart_product_prices.price * cscart_product_prices.percentage_discount
)/ 100
)
)
) AS price
FROM
cscart_product_prices
LEFT JOIN cscart_master_products_storefront_min_price ON cscart_master_products_storefront_min_price.product_id = cscart_product_prices.product_id
AND cscart_master_products_storefront_min_price.storefront_id = 1
WHERE
cscart_product_prices.product_id IN (
8772, 7307, 6831, 6881, 7306, 7230, 7321,
8611, 7878, 12093, 7775, 7231, 8051,
8429, 19430, 19432, 19424, 19431, 8612,
16492, 16493, 10045, 10049, 16494
)
AND cscart_product_prices.lower_limit = 1
AND cscart_product_prices.usergroup_id IN (0, 1)
GROUP BY
cscart_product_prices.product_id