seth aruby7,621 Points
Making query account for unknown PERIODS count
Shouldn't this query be written such that it is PERIODS count agnostic? Yes, the comment in the example tells you there are 7 periods but it seems like it would be better to have within the query some sort of check on the PERIODS table for the actual count of PERIODS currently in the db?
Are you saying you want a way for the database to tell you how many periods are possible without the teacher telling you ahead of time? In that case, you can write a query to return the highest period number like this:
SELECT MAX(PERIOD_ID) AS HIGHEST_NUMBER FROM TEACHERS JOIN CLASSES ON TEACHERS.ID = CLASSES.TEACHER_ID
Then you can change the query back to the way the teacher shows to retrieve the records matching the maximum period number.