I need to return a list of students with the respective task results, however, students can repeat the task, this means that there are duplicates. I want to get the first result but I want to get the first result from all the students in the class.
My current query that returns all the results including duplicates is:
SELECT student_id, attempt_id, task_score
FROM Attempt JOIN SetPaper ON Attempt.paper_id = SetPaper.paper_id
WHERE SetPaper.task_id = {X} AND class_id = {Y} AND task_status = "complete";
Where 'X' and 'Y' are predetermined variables.
This currently will return:
+------------+------------+------------+
| student_id | attempt_id | task_score |
+------------+------------+------------+
| X0000 | 1 | 70 |
| X0001 | 2 | 40 |
| X0001 | 3 | 50 |
+------------+------------+------------+
This is because in this case student 'X0001' has attempted and completed the task twice. However, I want it in the format:
+------------+------------+------------+
| student_id | attempt_id | task_score |
+------------+------------+------------+
| X0000 | 1 | 70 |
| X0001 | 2 | 40 |
+------------+------------+------------+
So that it only gets their first attempts results.
I have tried using DISTINCT(student_id) but that still gets the other results if I want to return more that just the student id's.
Thanks,
Ryan.