Exclude suspend users from SQL query

Re: Exclude suspend users from SQL query

by Randy Thornton -
Number of replies: 0
Picture of Documentation writers


You should look at using a LEFT JOIN (or sometimes a RIGHT JOIN) instead of the default or INNER JOINs.

This is the usual solution to issues where you need all the data from one side of the join even if it is empty or missing on the other side.

The INNER JOIN says, "show me all A and B", that is the union of them (in set terminology). Now, if one side of the data is missing (commonly in Moodle things like grade items, activity completion, or course completion that will only exist when actually done) then you can get around that with LEFTJOIN which says "show me everything in table A *with* table B when there is any". So you see all table A data whether or not there is something in table B.


Search for "LEFT JOIN" in the contributed reports page and you will see some really nice examples of how to do this: https://docs.moodle.org/35/en/ad-hoc_contributed_reports




Average of ratings: Useful (2)