CREATE TABLE activities(activityid, name);
CREATE TABLE activity_scores(activityid, studentid, score);
CREATE TABLE students (id, name);
Is there any way to write a single SELECT query that will produce one result for each student, in this format?
studentid | studentname | activity1_score | activity2_score | activity3_score [...]
It's trivial to do it with multiple queries:
for each studentid in "select id from students":
print studentid
for each activity in "select activityid from activities":
select score from activity_scores where studentid = studentid
print score
(pseudocode, I know it's not accurate)
Surely there's a way to create this result with a single SELECT query, right?