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
The first query will give you everyone regardless of their role - the table is used to store the type of enrolment - http://docs.moodle.org/26/en/Enrolment_plugins
The second one will only give you students - so will be more useful.
They are the same results because only students have been assigned to the courses.
If you go to a course and enrol users. Then at the top of the popup window choose assign roles = teacher and enrol a user. So on the course you will now have student(s) and a teacher
Then re-run the queries, the second query will have fewer results because it will only have students.