by Hubert Chathi.
More functions that you can use for querying the database: http://docs.moodle.org/dev/Data_manipulation_API Also, make sure to read the section on recordsets if you need to deal with large results.