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

SQL Playground Issue

I'm having an issue where the columns do not match up with data in their respective column. All of the data appears, but the columns are off by two places.

SELECT * FROM TEACHERS "t"
JOIN CLASSES "c" ON t.ID = c.TEACHER_ID
JOIN SUBJECTS "s" ON s.ID = c.SUBJECT_ID
WHERE GRADE = 8;

I have a screenshot of the query and what it pulled from the database, but I can't post the photo. Any ideas?

4 Answers

Steven Parker
Steven Parker
231,172 Points

It seems to omit column names in the header if it was used before (even in a different table).

I used aliases to make all the column names unique, and the output looks as expected:

SELECT t.ID, t.FIRST_NAME, t.LAST_NAME,
       c.ID AS Class, c.SUBJECT_ID, c.PERIOD_ID, c.TEACHER_ID, c.ROOM_ID,
       s.ID AS Subject, s.NAME, s.GRADE, s.DESCRIPTION
FROM TEACHERS t
JOIN CLASSES c ON t.ID = c.TEACHER_ID
JOIN SUBJECTS s ON s.ID = c.SUBJECT_ID
WHERE GRADE = 8;

:crocodile:

Nice solution! Thank you for your help, Steven!

Steven Parker
Steven Parker
231,172 Points

Glad to help. It's still a bug that it doesn't work your way, I hope that gets fixed.

Happy coding!

Jason Anders
MOD
Jason Anders
Treehouse Moderator 145,860 Points

Hey Jackson,

I noticed that weird glitch too. It seems to be because the CLASS_ID (the PK from CLASSES shows up in his playground, but not the one we use. That seems to be why everything is shifted by one.

Tagging Ben Deitch for a fix. :)
Run the second and third query (with the two JOINS) and you'll see what we mean. :)

Edit: This also happens in the next video's playground as well.

:dizzy:

Wonderful! Thank you for your help, Jason!

Ben Deitch
STAFF
Ben Deitch
Treehouse Teacher

Hey all!

This seems to be a bug with SQL Playgrounds. Between those three tables selecting * should give you 12 columns. However, 3 of those columns are 'ID', and it looks like it's only willing to display 1 'ID' column :/. I'll follow up with the folks who maintain SQL Playgrounds and see if we can't figure out a solution.

Thanks for pointing this out!

Mary Urban
Mary Urban
6,321 Points

I had that issue in the last lesson, then I realized if I always click on the current playground associated with the section I am working on, it works just fine. When I tried this lesson, it worked for me. Hopefully this helps - unless it had already been fixed by now and that's why this is working for this lesson.