Currently we use the following query to identify students who are enrolled in a course, but should not be:
"SELECT u.username, u.firstname, u.lastname, c.idnumber, c.fullname, r.id, r.roleid, r.contextid, r.userid "
"FROM mdl_user AS u INNER JOIN mdl_role_assignments AS r ON u.id = r.userid INNER JOIN mdl_context AS co ON r.contextid = co.id INNER JOIN mdl_course AS c ON c.id = co.instanceid "
"WHERE (c.idnumber = '" & w_course_id & "') AND (r.roleid IN ('3','5')) "
The problem we've experienced is when a student is enrolled and active in a course, but does not have a role assigned.
Does anyone know of a good way to join contextID and instanceID without using mdl_role_assignments? Is there a different query we could use to identify students even if they do not have a role assigned?
We are currently using Moodle 3.3.3, Windows 2016, and SQL Server 2014
Thanks