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
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.)