I'm pretty new to sql, so forgive me if there's a simple answer. I'm setting up a scheduling database for lessons in a school. Each class has between 3 and 9 students. I was originally planning to use two tables with a JOIN as follows:
Table 1: Class Day-of-week Start-time End-time Student1 ... Student9
JOIN
Table 2: Date Class Teacher
This would give a list of all the classes by date. The problem is that if a new student joins the class, updating Table 1 would add that student to all the previous rows although the student didn't attend those classes. Is there a better (and simple) way to set up the schedule which preserves the data in past rows?
*edit It's not so much a problem with the code, but more of a data organization problem. (I've included the code I'm using below).
Table 1: Class Day-of-week Start-time End-time S1 S2 S3... S9
English Mon 8:00 9:00 Jon Sue Null....Null
Table 2: Date Class Teacher
2019-01-07 English ProfX
2019-01-14 English ProfY
2019-01-21 English ProfZ
Then the JOIN looks like
Schedule
2019-01-07 English ProfX Mon 8:00 9:00 Jon Sue Null....Null
2019-01-14 English ProfY Mon 8:00 9:00 Jon Sue Null....Null
2019-01-21 English ProfZ Mon 8:00 9:00 Jon Sue Null....Null
Now assume a new student (Tim) joins for the next class. If I update Table 1 with the new student, all of the previous rows would include Tim, but he wasn't in the class for 2019-01-07 or 2019-01-14, so my table would look like this.
2019-01-07 English ProfX Mon 8:00 9:00 Jon Sue Tim....Null
2019-01-14 English ProfY Mon 8:00 9:00 Jon Sue Tim....Null
2019-01-21 English ProfZ Mon 8:00 9:00 Jon Sue Tim....Null
When I only want this:
2019-01-07 English ProfX Mon 8:00 9:00 Jon Sue Null....Null
2019-01-14 English ProfY Mon 8:00 9:00 Jon Sue Null....Null
2019-01-21 English ProfZ Mon 8:00 9:00 Jon Sue Tim....Null
////code////
Create VIEW 'schedule' SELECT Table1.*, Table2.*
FROM Table1
INNER JOIN Table2
ON (Table1.class = Table2.class);