select * from(
select DISTINCT p.products_price * if(gz.geo_zone_id is null, 1, 1 + (tr.tax_rate / 100) ) as priceWithTax, p.products_image, IF(p.id_product_grouper, mpg.product_name, pd.products_name) as products_name, IF(pd.products_alt_image != '', pd.products_alt_image, pd.products_name) as products_alt_image, p.products_id, p.products_quantity, p.products_ignore_stock, p.manufacturers_id, p.products_label_id, p.products_price, p.products_price_b, p.products_price_c, p.products_tax_class_id, p.order_in_grouper as order_ig, IF(s.status, s.specials_new_products_price, NULL) AS specials_new_products_price, IF(s.status, s.specials_new_products_price, p.products_price) AS final_price, s.percentage, IF(p.id_product_grouper, CONCAT('g_', p.id_product_grouper), p.products_id) as group_id, (p.id_product_grouper is NULL) as grouper, IF(cdPar.url_amigable != '', CONCAT(cdPar.url_amigable, '/', cd.url_amigable,'/',pd.url_amigable,'.html'), CONCAT(cd.url_amigable,'/',pd.url_amigable,'.html')) AS urlProducto, cd.categories_name as categoria, m.manufacturers_name , concat('-', group_concat(CONCAT(pa.options_id, '_',pa.options_values_id , '_', pa.options_value_text) SEPARATOR '-'), '-') options_values
FROM products_description pd, products p
LEFT JOIN products_attributes pa on pa.products_id = p.products_id left join tax_rates tr on p.products_tax_class_id = tr.tax_class_id left join zones_to_geo_zones gz on tr.tax_zone_id = gz.geo_zone_id and (gz.zone_country_id is null or gz.zone_country_id = '0' or gz.zone_country_id = '10') and (gz.zone_id is null or gz.zone_id = '0' or gz.zone_id = '169')
LEFT JOIN mods_product_groupers mpg ON p.id_product_grouper = mpg.id
LEFT JOIN manufacturers m ON p.manufacturers_id = m.manufacturers_id
LEFT JOIN specials s ON p.products_id = s.products_id, products_to_categories p2c
LEFT JOIN categories c ON p2c.categories_id = c.categories_id
LEFT JOIN categories_description cd ON cd.categories_id = c.categories_id
LEFT JOIN categories cPar ON cPar.categories_id = c.parent_id
LEFT JOIN categories_description cdPar ON cPar.categories_id = cdPar.categories_id
WHERE p.products_status = '1'
AND p.products_id = p2c.products_id
AND pd.products_id = p2c.products_id
AND p.deleted = 0
AND pd.language_id = '2'
AND (c.parent_id = '0' OR p2c.categories_id = '0')
and (c.hide_without_stock = 0 or p.products_quantity > 0 or p.products_ignore_stock = 1) AND m.manufacturers_id = 35 group by p.products_id having
ORDER BY products_quantity DESC, order_ig ASC) as tabla group by group_id ORDER BY CASE WHEN products_quantity < 1 THEN 0 WHEN products_quantity >= 1 THEN 2 END desc , priceWithTax ASC, products_name