SELECT * FROM (SELECT 
                    DISTINCT p.productID,
                    IF (cp.price IS NOT NULL, cp.price , p.basePrice) as basePrice,
                    IF (cp.price IS NOT NULL, cp.priceBon , p.basePriceBon) as basePriceBon
                    , p.typeID
                    , p.dealPriceCur
                    , pt.name as typeName
                    , p.dealPriceBon
                    , p.categoryID
                    , i.name as intensity
                    , t.color
                    , p.name
                    , p.ranking
                    , p.code
                    , cp.price as cpprice
                    , btn.buttonNameID
                    , btn.buttonName
                    , btna.buttonActionID
                    , p.publishCur
                    , p.publishBon                    
                    , d.availableCur
                    , p.gridIteration
                    , d.availableBon
                    , IF (d.availableCur IS NOT NULL, d.availableCur , p.deal) as deal
                    FROM product as p
                    LEFT JOIN categories as cat on p.categoryID = cat.categoryID
                    LEFT JOIN intensity as i on i.intensityID = p.intensityID
                    LEFT JOIN producttype as pt on pt.typeID = p.typeID
                    LEFT JOIN deals as d on d.productID = p.productID
                    LEFT JOIN productsubcategory as psub on psub.productID = p.productID
                    LEFT JOIN productgrape as pg on pg.productID = p.productID
                    LEFT JOIN customerproduct as cp on cp.productID = p.productID AND cp.customerID = 0
                    LEFT JOIN tasteprofile as t on p.tasteprofileID = t.tasteprofileID
                    LEFT JOIN buttonname as btn on p.buttonNameID = btn.buttonNameID
                    LEFT JOIN buttonaction as btna on p.buttonActionID = btna.buttonActionID
                     WHERE p.active = '1' AND cat.nameID = ? AND subcategoryID IN (?) AND p.publishCur != '0' ) as ta  ORDER BY name, productID  LIMIT 60, 12