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 `a`.`id` IN (SELECT `cm`.`instance` FROM mdl_course_modules cm WHERE `cm`.`i' at line 1