I don't know if other people need to do this, or if it is just me.
However, sometimes you are querying the database to find all the questions that have a certain property, and then you want to know where they are. That is complex, because sometimes there are in the course area of the questions bank, and sometimes they are in the area for a particular quiz.
Anyway, you can detangle it, and it is worth knowing how. See below.
Also, you can construct a nice link to takes you do the right bit of the question bank, with the relevant question highlighted.
c.shortname AS course,
qc.name AS question_category,
q.name AS question,
CASE WHEN cm.id IS NULL THEN 'courseid=' || c.id ELSE 'cmid=' || cm.id END ||
'&category=' || qc.id || '%2C' || ctx.id ||
'&qperpage=1000&lastchanged=' || q.id
FROM mdl_question q
LEFT JOIN mdl_question_categories qc ON qc.id = q.category
LEFT JOIN mdl_context ctx ON ctx.id = qc.contextid
LEFT JOIN mdl_course_modules cm ON cm.id = ctx.instanceid AND ctx.contextlevel = 70
LEFT JOIN mdl_course c ON (ctx.contextlevel = 50 AND c.id = ctx.instanceid)
OR (ctx.contextlevel = 70 AND c.id = cm.course)
WHERE questiontext LIKE '%mispeld%'
ORDER BY c.shortname, qc.name, q.name
Just thought some of you might find that useful. I guess I ought to put this on the wiki somewhere.