I am working on a "builder" where we can add elements to build a quiz.
An element represents a block (a text, a question, a video etc) in the quiz. Each element can be linked to multiple exams with a position in this exam. When creating an element, in my form I can select multiple exams (from the exam
table) and enter, for each exam a position (as a number).
I would like to be able to list in a table (in the front-end) all the elements with a column name for each exam name, and below each exam name, the position I entered in the form.
I have actually written this query :
SELECT
e.id AS element_id,
e.name AS element_name,
ee.position,
se.title AS exam_title
FROM element e
LEFT JOIN element_exams ee
ON e.id = ee.element_id
LEFT JOIN subject_exam se ON se.id = ee.exam_id
GROUP BY e.id
Which gives this result :
However, instead of "exam_title" as a column name, I would like to actually have "AQA Only" and below the position (1.12). And this, for each exam I have in my "exam" table. So for example, if I have 3 exams named (AQA Only, Exam 2, Exam 3), I would like to have a table result with :
element_id | element_name | AQA Only | Exam 2 | Exam 3
And below each exam name, the position I entered in the form.
Is it possible? Basically, I want to have a select query with dynamic column name based on the values of another table.
Thanks!