Welcome to the Treehouse Community

The Treehouse Community is a meeting place for developers, designers, and programmers of all backgrounds and skill levels to get support. Collaborate here on code errors or bugs that you need feedback on, or asking for an extra set of eyes on your latest project. Join thousands of Treehouse students and alumni in the community today. (Note: Only Treehouse students can comment or ask questions, but non-students are welcome to browse our conversations.)

Looking to learn something new?

Treehouse offers a seven day free trial for new students. Get access to thousands of hours of content and a supportive community. Start your free trial today.

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;