SELECT SQL_CALC_FOUND_ROWS * ,LEAST(IF(price1_1 > 0, (price1_1 * (1-(discount/100))),9999), IF(price2_1 > 0, (price2_1 * (1-(discount/100))),9999), IF(price3_1 > 0, (price3_1 * (1-(discount/100))),9999), IF(price4_1 > 0, (price4_1 * (1-(discount/100))),9999), IF(price5_1 > 0, (price5_1 * (1-(discount/100))),9999), IF(price6_1 > 0, (price6_1 * (1-(discount/100))),9999)) AS priceMin FROM `jos_virtuemart_products_en_gb` as l JOIN `jos_virtuemart_products` AS p using (`virtuemart_product_id`) LEFT JOIN `jos_productPrices` ON p.`virtuemart_product_id` = `jos_productPrices`.`product_id` LEFT JOIN `jos_productDetails` ON p.`virtuemart_product_id` = `jos_productDetails`.`product_id` LEFT JOIN `jos_virtuemart_product_categories` ON p.`virtuemart_product_id` = `jos_virtuemart_product_categories`.`virtuemart_product_id` LEFT JOIN `jos_virtuemart_categories_en_gb` as c ON c.`virtuemart_category_id` = `jos_virtuemart_product_categories`.`virtuemart_category_id` WHERE ( p.`published`="1" AND ( `jos_virtuemart_product_categories`.`virtuemart_category_id` = 356 OR `jos_virtuemart_product_categories`.`virtuemart_category_id` = 357 OR `jos_virtuemart_product_categories`.`virtuemart_category_id` = 358 OR `jos_virtuemart_product_categories`.`virtuemart_category_id` = 359 OR `jos_virtuemart_product_categories`.`virtuemart_category_id` = 360)) group by p.`virtuemart_product_id` ORDER BY `ordering` ASC