I am using the Moodle database to query the latest forum posts made by students and teachers for the relevant course they are enrolled in.
Here are the tables I need to join and an explanation in what they hold:
mdl_forum_posts = "all posts are stored in this table"
mdl_forum_discussions = "forums are composed as discussions"
mdl_user = "information stored about users"
mdl_log = "activity of every user of the system be it, log in - adding a post"
mdl_user_enrolments = "users participating in courses"
mdl_enrol = "instances of enrolment plugins used in mdl_course"
mdl_course = "courses available in the system"
Here is my query:
SELECT l.time AS TimeofPost, l.action as Action, usr.id as UserID,
usr.firstname,usr.lastname, c.id as CourseID , c.fullname,
c.idnumber, fd.name, fd.timemodified as CreatedOn, fp.created,
fp.modified, fp.subject, fp.message
FROM mdl_forum_posts fp
LEFT JOIN mdl_forum_discussions fd ON fp.discussion = fd.id
LEFT JOIN mdl_user usr ON fp.userid = usr.id
LEFT JOIN mdl_log l ON usr.id = l.userid
LEFT JOIN mdl_user_enrolments ue ON usr.id = ue.userid
LEFT JOIN mdl_enrol e ON ue.enrolid = e.id
LEFT JOIN mdl_course c ON e.courseid = c.id
WHERE (action = 'add post' OR action = 'add discussion')
The problem I have is that I am getting duplicate results.