INVALID SQL: 1064 : 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 'then 1 when xcart_products_categories.categoryid = 371 or xcart_products_categor' at line 1 SQL QUERY FAILURE: SELECT DISTINCT xcart_products.productid, cannotbeadded, xcart_products.productcode, MIN(xcart_pricing.price) AS price, xcart_products.product FROM (xcart_products, xcart_pricing) left join xcart_products_categories on xcart_products_categories.productid = xcart_products.productid WHERE xcart_pricing.productid=xcart_products.productid AND xcart_pricing.quantity=1 AND xcart_pricing.variantid = 0 AND (xcart_pricing.membership='' OR xcart_pricing.membership='') AND xcart_products.forsale='Y' and xcart_products.productid not in ( 17518, 17919, -1 ) GROUP BY xcart_products.productid ORDER BY case when xcart_products_categories.categoryid = then 1 when xcart_products_categories.categoryid = 371 or xcart_products_categories.categoryid in ( 547, 762 ) then 3 else 2 end , rand() limit 4 Jonathan Adler in