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 ') group by cl.league_name' at line 1 in: [select /*tpl_categories_new.php*/ distinct cl.league_name, cm.category_id from category_league as cl join category_continent_map as cm on cm.team_id = cl.id where cl.type = 'l' and cm.category_id in () group by cl.league_name]