I'm working through an inner join example on Geeks For Geeks I came across a SELECT statement I don't understand.
We have two tables, Student and StudentCourse we are joining on a common column ROLL_NO.
SELECT StudentCourse.COURSE_ID, Student.NAME, Student.AGE FROM Student
INNER JOIN StudentCourse
ON Student.ROLL_NO = StudentCourse.ROLL_NO;
My question is why the SELECT statement specifies one column from StudentCourse and two from Student, but then only says FROM Student. Shouldn't it also need to say FROM StudentCourse to get access to those columns? Why is that in scope?
I think this command can be better read as:
SELECT StudentCourse.COURSE_ID, Student.NAME, Student.AGE
FROM Student
INNER JOIN StudentCourse
ON Student.ROLL_NO = StudentCourse.ROLL_NO;
You're not selecting from Student, but the joined table of Student and Student Course. Think of them as having joined into one table. This combined table has all of the columns of Student and Student Course from which we're selecting three.