Looking for feedback on query to return instructors from only meta courses within given category

Looking for feedback on query to return instructors from only meta courses within given category

yazan Bobby Siegfried -
Yanıt sayısı: 1

I've been working on a single SQL query to pull all Teachers (some courses have multiple) as well as course short name and only meta as the enrol type. I've got a working query, but it seems very inefficient to me. Would love some feedback and suggestions from a more skilled db admin. I'm sure I'm missing an obvious concept that would simplify and make this query much more efficient. Thanks in advance!

select distinct u.username, u.email, u.firstname, u.lastname, c.shortname, e.enrol
from mdl_user u
join mdl_role_assignments ra on ra.userid = u.id
join mdl_context x on x.id = ra.contextid
join mdl_course c on c.id = x.instanceid
join mdl_enrol e on e.courseid = c.id
where u.id in (
    select distinct r.userid
    from mdl_role_assignments r
    inner join mdl_context x on r.contextid = x.id
    inner join mdl_course c on x.instanceid = c.id
    where x.contextlevel = 50
    and c.category = 655
    and r.roleid = 3
    and c.id in (
        select distinct e.courseid
        from mdl_enrol e
        left join mdl_course c on c.id = e.courseid
        where e.enrol = "meta"
        and c.category = 655
    )
)
and c.id in (
    select distinct e.courseid
    from mdl_enrol e
    left join mdl_course c on c.id = e.courseid
    where e.enrol = "meta"
    and c.category = 655
)
and e.enrol = "meta"
Bobby Siegfried yanıt olarak

Re: Looking for feedback on query to return instructors from only meta courses within given category

yazan Paul Holden -
Core developers 'ın resmi Moodle HQ 'ın resmi Moodle Workplace team 'ın resmi Particularly helpful Moodlers 'ın resmi Peer reviewers 'ın resmi Plugin developers 'ın resmi Testers 'ın resmi

Hi Bobby, you could create the same type of report using custom reports:

Custom report editor

If you want to see the SQL that is generated for the report, you can toggle the "Debug info" panel - it should help you in amending your own and removing all those derived table sub-selects you currently have