Skip to content

Instantly share code, notes, and snippets.

@georgekinnear
Last active January 27, 2026 16:01
Show Gist options
  • Select an option

  • Save georgekinnear/107e5a1419e8bcbd01efde2227fcd823 to your computer and use it in GitHub Desktop.

Select an option

Save georgekinnear/107e5a1419e8bcbd01efde2227fcd823 to your computer and use it in GitHub Desktop.
Moodle SQL: All attempt steps in a quiz - not just the last for each student
SELECT
qa.*,
qas_last.*,
qas_last.timecreated AS stepdate,
u.email,
u.firstname,
u.lastname
FROM {course_modules} cm
JOIN {quiz_attempts} quiza ON quiza.quiz = cm.instance
JOIN {question_usages} qu ON qu.id = quiza.uniqueid
JOIN {question_attempts} qa ON qa.questionusageid = qu.id
LEFT JOIN {question_attempt_steps} qas_last ON qas_last.questionattemptid = qa.id
LEFT JOIN {user} u ON qas_last.userid = u.id
WHERE
cm.id = :quiz_id
ORDER BY
u.username,
qas_last.timecreated
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment