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 1: Joining Tables 8th Grade Teachers

Frances Angulo
Frances Angulo
5,311 Points

My solution returned more results

select DISTINCT teachers.first_name as Teacher_first, teachers.last_name as Teacher_last, students.grade from students join schedule on students.id = schedule.student_id join classes on schedule.class_id = classes.id join teachers on classes.teacher_id = teachers.id where students.grade = 8

You got ~6 teachers and I got many more- what is my query actually returning?

3 Answers

Steven Parker
Steven Parker
218,833 Points

The original question was "Which teachers teach only students in 8th grade?"

I believe this query answers the question "Which teachers teach any students in 8th grade?"

Frances Angulo
Frances Angulo
5,311 Points

ahhhhh that makes sense. Thank you!

-- Which teachers teach only students in 8th grade
  SELECT distinct TEACHERS.First_name, Teachers.Last_name
  FROM Teachers JOIN
  Classes ON Teachers.ID = Classes.Teacher_ID
  JOIN Subjects
  ON Subjects.ID = Classes.Subject_ID
  where subjects.grade=8
  order by First_name, Last_name