SELECT Count(DISTINCT productId) as rowCount FROM product P LEFT JOIN product_sub_category C ON P.categoryId = C.categoryId WHERE C.categoryId = MySql #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 '' at line 1