I have run the following test, and I get some rows, so my test fails, I have some rows that has contexid that is missing in context table.
How does it happened and how can we avoid it ?
Question categories should all belong to a valid context
This applies from 1.9 onwards. The following query should return no records.
SELECT qc.*, (SELECT COUNT(1) FROM mdl_question q WHERE q.category = qc.id) AS numquestions FROM mdl_question_categories qc LEFT JOIN mdl_context con ON qc.contextid = con.id WHERE con.id IS NULL