Welcome to the Treehouse Community

Want to collaborate on code errors? Have bugs you need feedback on? Looking for an extra set of eyes on your latest project? Get support with fellow developers, designers, and programmers of all backgrounds and skill levels here with the Treehouse Community! While you're at it, check out some resources Treehouse students have shared here.

Looking to learn something new?

Treehouse offers a seven day free trial for new students. Get access to thousands of hours of content and join thousands of Treehouse students and alumni in the community today.

Start your free trial

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;