I have THREE tables:
Table_1 with student names (fields = StudentID, FirstName, LastName)
Table_2 with teacher names (fields = TeacherID, FirstName, LastName, Initials*) (*The 'Initials' field holds each teachers initials: 'JD' for 'John Doe', 'FB' for 'Fred Bloggs', etc)
Table_3 with the grades that each teacher gave each student (fields = StudentID, TeacherID, Grade)
I would like to generate a query that lists all the students, along with their grades; something like:
FirstName | LastName | JD | FB
==============================
Paul | Smith | 7 | 8
Nancy | Brown | 5 | 4
Chris | Nobody | 6 | 9
The problem is that the columns after FirstName and LastName should be generated "dynamically" from the contents of Table_2 (the teachers giving out the grades). In other words, if a new teacher is added to that table (say, Zack Zanny), then (after he has graded all the students) the same query should yield something like:
FirstName | LastName | JD | FB | ZZ
===================================
Paul | Smith | 7 | 8 | 3
Nancy | Brown | 5 | 4 | 1
Chris | Nobody | 6 | 9 | 2
Did I make this clear?
I've searched this forum and others and I've tried reading up on mysql pivot tables but I must be doing something wrong... Any pointers would be much appreciated. Thanks in advance.