SQL Report Query

SQL Report Query

by Jonny Douglas -
Number of replies: 1

Hi everyone.

I'm new to Moodle and I've to run few sql queries in order to gain some information. There is one I'm very stuck on, even after working through and adjusting the ad-hoc reports.

I'm trying to figure gain the institutions/institutes that are using or enrolled on a particular course.

Anyone have any suggestions for a sql query that could return the answer?

Thanks!

Average of ratings: -
In reply to Jonny Douglas

Re: SQL Report Query

by Mayank Tyagi -
Hey Jonny ,

I think you want a query by which you can fetch all the users (institute) enrolled in particular course. You can do it by many ways.
1) use get_enrolled_users(parameter) function. It will give you the list of enrolled users in particular course.
2) use enrol_get_course_users(parameter)
3)Direct hit this query. It will give you all the information of enrooled users in particular course.
 SELECT ue.id AS ueid, ue.userid as user, ue.status AS uestatus, e.courseid as course,ue.enrolid AS ueenrolid, ue.timestart AS uetimestart,
             ue.timeend AS uetimeend, ue.modifierid AS uemodifierid, ue.timecreated AS uetimecreated,
             ue.timemodified AS uetimemodified,
             u.username FROM mdl_user_enrolments ue
              JOIN mdl_enrol e ON e.id = ue.enrolid
              JOIN mdl_user u ON ue.userid = u.id where e.courseid = $courseid

Thanks,

Mayank Tyagi