SQL: Looking for relation between questions and question categories

SQL: Looking for relation between questions and question categories

by Ingo Marzolph -
Number of replies: 4

Hello,

want to build a SQL query to get a list of all questions in a question bank that is used in a course.

I understand that I could recieve this via the question category but I am struggeling to find the proper tables that I could join to get the relation between a question and the category.

All forum posts are referring to question.categories but this doesn´t seem to exist anymore (the post were pretty old).
Also the documentations here https://docs.moodle.org/dev/Question_database_structure and here https://docs.moodle.org/dev/Quiz_database_structure are telling me that the tables are linked via the category.

The relation must be moved to somewhere else but I can´t find it.

I would be really happy if someone give me a hint in the right direction.

Thanks,

Ingo

-----

Note: My complete goal is to have a query where I can also see if the question is hidden or not and if it is used in any of the quizzes inside a course. Maybe had a similar requirement in the past and can help me out.

Average of ratings: Useful (1)
In reply to Ingo Marzolph

Re: SQL: Looking for relation between questions and question categories

by Marcus Green -
Picture of Core developers Picture of Particularly helpful Moodlers Picture of Plugin developers Picture of Testers
In reply to Marcus Green

Re: SQL: Looking for relation between questions and question categories

by Ingo Marzolph -
Hello Marcus,

thanks for the hint. I actually was working my way through this website. Great work! It is really helpfull.

But the only connection that I found from questions to the question_bank_entries tables was via the question_dataset tables.
Sadly those tables are completely empty in my MySQL table.

I can´t go over the quiz table, since I want to see also the questions in the question bank in a course that is not assigned to a quiz, so that we can find the unused questions.
In reply to Ingo Marzolph

Re: SQL: Looking for relation between questions and question categories

by Tim Hunt -
Picture of Core developers Picture of Documentation writers Picture of Particularly helpful Moodlers Picture of Peer reviewers Picture of Plugin developers
The change in database structure is outlined in this forum post: https://moodle.org/mod/forum/discuss.php?d=417599#p1683186

The kind of joins you need can be found is various bits of code now. Here is one example https://github.com/studentquiz/moodle-mod_studentquiz/blob/5f2302fa6c73b9b512f747eca82b294092f4ca2a/locallib.php#L899