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 'AND search_category_id= ORDER BY `rank` LIMIT 0, 40' at line 1, query was SELECT job_id AS id FROM tblSearchCategories_JobsByCity WHERE country_id=236 AND city_id= AND search_category_id= ORDER BY `rank` LIMIT 0, 40