Here is a description of the table i am using:
describe mjla_db.StudentRecordTable2;
+-----------+-------------+------+-----+---------+-------+
| Field | Type | Null | Key | Default | Extra |
+-----------+-------------+------+-----+---------+-------+
| classId | varchar(20) | NO | MUL | NULL | |
| studentId | varchar(20) | NO | MUL | NULL | |
| quizGrade | tinyint(4) | YES | | NULL | |
| quizId | int(11) | NO | MUL | NULL | |
+-----------+-------------+------+-----+---------+-------+
4 rows in set (0.00 sec)
Here is example data in the database:
+------------+-----------+------------+---------+------------+
| Student ID | Last Name | First Name | Quiz ID | Quiz Grade |
+------------+-----------+------------+---------+------------+
| A1 | Cat | Tom | 19 | 75 |
| A2 | pancake | Harry | 19 | 65 |
| A5 | Worthy | Dick | 19 | NULL |
| A1 | Cat | Tom | 20 | 55 |
| A2 | pancake | Harry | 21 | NULL |
| A2 | pancake | Harry | 20 | 47 |
| A5 | Worthy | Dick | 20 | 95 |
| A1 | Cat | Tom | 21 | 55 |
| A5 | Worthy | Dick | 21 | 95 |
+------------+-----------+------------+---------+------------+
3 rows in set (0.00 sec)
The result i am trying to get is one that will look similar to the following:
+------------+-----------+------------+---------+------------+------------+
| Student ID | Last Name | First Name | Quiz 19 | Quiz 20 | Quiz 21 |
+------------+-----------+------------+---------+------------+------------+
| A1 | Cat | Tom | 75 | 55 | 55 |
| A2 | pancake | Harry | 65 | 47 | NULL |
| A5 | Worthy | Dick | NULL| 95 | 95 |
+------------+-----------+------------+---------+------------+------------+
- Where the Student ID column is unique.
- Where the quiz columns continue depending on how many quizzes are in the original table. And the quiz columns contain the grade of each of the respective students.