Para extrair todas as mensagens publicadas no fórum de todos os cursos com comando SQL, execute o comando a seguir.
SELECT DISTINCT p.id,p.created AS timecreated,p.subject,p.message,p.mailnow, u.id AS userid,u.firstname, u.lastname,u.email,r.name AS rolename,r.shortname AS roleshortname,c.id AS courseid,c.fullname,ct.name AS coursecategoryname, ct.id coursecategoryid FROM mdl_forum_posts p INNER JOIN mdl_user u ON p.userid=u.id INNER JOIN mdl_forum_discussions d ON d.id=p.discussion INNER JOIN mdl_forum f ON f.id =d.forum INNER JOIN mdl_course c ON c.id=f.course INNER JOIN mdl_course_categories ct ON c.category=ct.id INNER JOIN mdl_role_assignments rs ON rs.userid=p.userid INNER JOIN mdl_role r ON rs.roleid=r.id INNER JOIN mdl_context e ON rs.contextid=e.id INNER JOIN mdl_enrol en ON e.instanceid=en.courseid INNER JOIN mdl_user_enrolments ue ON en.id=ue.enrolid WHERE e.contextlevel=50 AND e.instanceid=f.course AND u.id=ue.userid
Esse comando foi extraído do MReport. Um relatório geral de todas as discussões e comentários publicadas no fórum do Moodle