query to find how student enrolled many different ways and update them via sql to use 'manual' enrolment only

Re: query to find how student enrolled many different ways and update them via sql to use 'manual' enrolment only

by Rick Jerz -
Number of replies: 0
Picture of Particularly helpful Moodlers Picture of Testers
What I once discovered is that as I was writing queries to see who was in a course, students with double-enrollments showed twice. What I had discovered is that some students would self-enrol, then email me saying they couldn't get in. My quick fix was to manually enroll them. However, this was creating double enrollments. Now, I simply make sure that I have students enrolled only once.

(Seems like I once wrote a query for this, but can't find it.)

Just created it...  but a little rough.

I think that this query will show students who have more than one enrollment in a course.

SELECT c.fullname AS Course_Name,
       u.id, u.lastname, u.firstname,
       count(u.id ) AS COUNT
FROM mdl_course c
JOIN mdl_enrol en ON en.courseid = c.id
JOIN mdl_user_enrolments ue ON ue.enrolid = en.id
JOIN mdl_user u ON u.id = ue.userid
JOIN mdl_role_assignments asg ON u.id = asg.userid
JOIN mdl_context con ON asg.contextid = con.id
WHERE ue.status = 0
  AND en.courseid = con.instanceid
GROUP BY c.id, u.id
having count > 1
ORDER BY c.id, count(*) DESC
Average of ratings: Useful (1)