Abstracted mdl_ and 'student'.
Added comments regarding permission required for query 1.3, also noted slow query.