Databases SQL Reporting by Example Day 3: Getting Good at Grouping Busiest Teachers

No Help needed but want to share Code with mistakes

I realized my mistake here but wanted to share it so others can reflect on it if they end up doing the same thing.

Instead of using the HAVING condition I used the WHERE BETWEEN.

-- Which teachers teach a class during all 7 periods?
SELECT DISTINCT FIRST_NAME,LAST_NAME FROM TEACHERS
JOIN CLASSES ON TEACHERS.ID = CLASSES.TEACHER_ID
WHERE PERIOD_ID BETWEEN 1 AND 7;

My mind was set on BETWEEN periods rather than the sum of the count. This returns all teachers rather than only teachers that teach all periods 1 through 7.

-- Which teachers teach a class during all 7 periods?
SELECT FIRST_NAME,LAST_NAME FROM TEACHERS
JOIN CLASSES ON TEACHERS.ID = CLASSES.TEACHER_ID
GROUP BY TEACHERS.ID HAVING COUNT(*) = 7;