I’m trying to display the information I have in these columns and it keeps telling me that the first_name column in my professors table is unknown. Does anyone know why?
Please help me, I’ve tried everything.
Thanks.
Here’s the query:
SELECT courses.name, sections.section_name, professors.first_name, professors.last_name, classrooms.room
FROM courses
INNER JOIN course_section ON sections.id = course_section.section_id
INNER JOIN professor_course ON professors.id = professor_course.professor_id
WHERE courses.id = 1;
The error is because you haven’t included sections in any from or join. You have the same thing going on with professors.
Personally, I prefer the readability of implied inner joins in this situation. A DBA may disagree, but as a programmer I find this easier to figure out what’s going on.
Not knowing your DB structure, you can probably get what you are looking for with less table joins.