I am quite an amateur with SQL (I am a teacher rather than programmer) and have written some code which worked in SQLITE but does not work in MYSQL. I have a table called 'scores' of student names, exercises and scores. As well as returning the completed exercises, I also wish to return those which are not completed. For this I used CROSS JOIN to generate all combinations of student and exercise. In SQLITE this returned null values for students that had not completed a particular exercise, which is useful.
Using this code in MYSQL, it complains that "Every derived table must have its own alias"
I understand this means that a subquery must have an 'AS ...' term. However, no matter where I add it, I still receive that error. I have tried online SQL 'validators' to help me, but still no success.
Can anybody help improve my code please ? Thank you
SELECT othertable.name , othertable.exercise, scores.score
from ((select distinct name from scores)
CROSS JOIN (select distinct exercise from scores)) AS othertable
left join scores
on(scores.name = othertable.name AND scores.exercise = othertable.exercise )
order by othertable.name, othertable.exercise