List of all quiz questions with correct answers

List of all quiz questions with correct answers

by Jeff Shrek -
Number of replies: 1

I need to get a list of questions with CORRECT answers.

I found this topic:
https://moodle.org/mod/forum/discuss.php?d=169011

It lists this SQL statement:

select

     quiz.name,

     q.questiontext, qa.answer

from mdl_quiz as quiz,

       mdl_question_answers as qa,

     mdl_question as q

where

quiz.id in (select id from mdl_quiz where course=1974)and

qa.question=q.id and

fraction>0 and

question in

    (select id

     from mdl_question

     where category=

        (

         select category

             from mdl_question

             where id = (select left(cast(questions as CHAR(10)),5)

             from mdl_quiz

             where id=quiz.id)

        )

    )


But the SQL statement generates the following error:

#1054 - Unknown column 'questions' in 'field list'


Since that original post was from 2011, is there a way to fix this statement or another way to do it?


Thanks

Average of ratings: -
In reply to Jeff Shrek

Re: List of all quiz questions with correct answers

by Tim Hunt -
Picture of Core developers Picture of Documentation writers Picture of Particularly helpful Moodlers Picture of Peer reviewers Picture of Plugin developers

That query makes several assumptions that are probably not true for most people: e.g. that the quiz is using random questions, and that the questionid contains 5 characters.

It will also only work for certain question types.

In later Moodle versions, the replacement for mdl_quiz.questions is the mdl_quiz_slots table. That partly answers your specific questions. However, to get a working query, you are going to have to make some assumptions specific to your situation.