SELECT t1.ProductId, t1.CategoryId, t1.CompanyId, t1.Name, t1.Picture, t1.Price, t1.PricePromotion, t1.Promotion, t1.Featured, t1.UrlKey, t1.InStock, t1.ShortDescription, t1.PostDate, categories.Name AS CategoryName, companies.Name AS CompanyName, companies.UrlKey AS CompanyUrlKey FROM (SELECT ProductId, CompanyId, CategoryId, Name, Picture, Price, PricePromotion, Promotion, Featured, UrlKey, InStock, ShortDescription, PostDate, FROM products WHERE Status = 0 AND 1 AND CategoryId IN (25) ORDER BY Featured DESC, Rand('1337558316') LIMIT 0,21 ) t1 LEFT JOIN categories ON categories.CategoryId = t1.CategoryId LEFT JOIN companies ON companies.CompanyId = t1.CompanyId (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 'FROM products WHERE Status = 0 AND 1 AND CategoryId IN (25) ORDER BY Feature' at line 5)