You have an error in your SQL syntax; check the manual that corresponds to your MySQL server version for the right syntax to use near 'group by a.prodid UNION ALL SELECT nul' at line 12

ERRORSQL: select sum(invqty) as invqty, sum(diinvqty) as diinvqty, catSort, CurrencyType,custPhotoVersion,ProdId,ProdNum,ProdPrice,ProdSalePrice, ManufPrice, ProdImage,ManufProd,ManufColId,LinkPrefix,manufSeqId, CatId,ProdShortDesc,prodURLOverride,colNameForTitles,productType,manufId,releaseDate,sort from ( SELECT sum(i.qty) as invqty, null as diinvqty, b.catSort, CurrencyType,custPhotoVersion,a.ProdId,ProdNum,ProdPrice,ProdSalePrice, ManufPrice, ProdImage,ManufProd,c.ManufColId,LinkPrefix,manufSeqId, CatId,ProdShortDesc,prodURLOverride,colNameForTitles,productType,c.manufId,releaseDate,a.sort FROM efashion_products AS a left join efashion_inventory as i on i.prodId=a.ProdId and i.qty>0 LEFT JOIN efashion_prod_cat AS b ON a.ProdId=b.ProdId LEFT JOIN efashion_manuf_cols AS c ON c.ManufColId=a.ManufColId WHERE a.ProductStatus=1 AND a.EfId=405 AND b.EfId=405 AND b.CatId= group by a.prodid UNION ALL SELECT null as invqty, sum(di.qty) as diinvqty, b.catSort, CurrencyType,custPhotoVersion,a.ProdId,ProdNum,ProdPrice,ProdSalePrice, ManufPrice, ProdImage,ManufProd,c.ManufColId,LinkPrefix,manufSeqId, CatId,ProdShortDesc,prodURLOverride,colNameForTitles,productType,c.manufId,releaseDate,a.sort FROM efashion_products AS a join efashion_inv_manuf_dedicated as di on a.ManufSeqId=di.seq LEFT JOIN efashion_prod_cat AS b ON a.ProdId=b.ProdId LEFT JOIN efashion_manuf_cols AS c ON c.ManufColId=a.ManufColId WHERE a.ProductStatus=1 AND a.EfId=405 AND b.EfId=405 AND b.CatId= and di.arrivalDate IS NULL group by a.prodid ) as sums group by prodid order by catSort DESC, invqty desc, diinvqty desc, ProdId ASC Limit 0,32