SQL query for Courses Enrolment on Moodle

后端 未结 5 601
清歌不尽
清歌不尽 2020-12-30 09:31

I was looking for the proper SQL queries for retrieving all students enrolled in a certain course, or all courses a certain student has enrolled in, on Moodle

5条回答
  •  灰色年华
    2020-12-30 10:12

    If you want to get the courses that an individual user is signed up for...

    SELECT c.id, c.shortname, c.summary, c.idnumber  
    FROM mdl_course c 
    JOIN mdl_enrol en ON en.courseid = c.id 
    JOIN mdl_user_enrolments ue ON ue.enrolid = en.id 
    WHERE ue.userid = '12345'
    AND  c.idnumber LIKE "blah%"
    

    (The last line is optional and can be used to filter for courses of a particular type. Note that idnumber is an optional and manually editable field.)

提交回复
热议问题