Skip to main content

SQL for returning only the latest quiz attempts

Comments

1 comment

  • Jason Rodgers

    Possibly something like this.  You could remove the WHERE condition for the course id to go system wide.

    ------

    SELECT 
    MQ.course, 
    MQ.name as QuizName,
    Concat('https://yourURL/mod/quiz/review.php?attempt=',MQA.id) AS link, 
    MQA.userid, 
    MAX(MQA.attempt) AS attempt 

    FROM mdl_quiz_attempts MQA
    INNER JOIN mdl_quiz MQ ON MQA.quiz=MQ.id
    LEFT JOIN mdl_quiz_grades QG ON QG.quiz=MQ.id
    WHERE MQ.course=9468 and QG.grade is NULL
    GROUP BY MQA.userid, MQA.quiz

    1

Please sign in to leave a comment.