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

Donnie Driskell
Donnie Driskell
2,243 Points

Reporting by example: 8th Grade Teachers. (my solution)

I might be wrong, but it seems that my particular query is shorter and returns values based on the teachers ID, F/L names and then grade at last column. I was wondering if this would work as an answer too ? thanks Donnie

SELECT DISTINCT ID, first_name, last_name, grade FROM teachers AS t JOIN (SELECT grade FROM students WHERE grade=8);

2 Answers

Using derived tables seems to work if you want a shorter query.

Select * from teachers where id in (select teacher_id from classes where subject_id in (select id from subjects where grade = 8))

I used this as well is this alright to do? Or should we use JOINING

SELECT DISTINCT TEACHERS.ID, FIRST_NAME, LAST_NAME FROM TEACHERS 
WHERE ID IN(SELECT TEACHER_ID FROM CLASSES 
WHERE SUBJECT_ID IN(SELECT ID FROM SUBJECTS 
WHERE GRADE = 8));
Ashley Carpenter
Ashley Carpenter
13,393 Points

Hi Donnie, I haven't tried it but that doesn't look it would be a valid query. You're missing some key parts like the 'on' part of your SQL join and a where clause to narrow the search just to 8th grade teachers. Go back to the challenge/video, open up the workspace and give it a bash.