I am trying to get instructors who are teaching students that live in same zipcode as the instructor.
First I found what zipcodes were shared by students and instructors using intersect.
SELECT DISTINCT FIRST_NAME,LAST_NAME,PHONE
FROM INSTRUCTOR
WHERE ZIP IN (
SELECT ZIP
FROM STUDENT
INTERSECT
SELECT ZIP
FROM INSTRUCTOR
);
than how can I find the section_id's for all students that where in the query above ?
SELECT SECTION_ID
FROM STUDENT s
JOIN ENROLLMENT e ON s.STUDENT_ID = e.STUDENT_ID
JOIN SECTION w ON e.SECTION_ID = w.SECTION_ID
JOIN INSTRUCTOR z ON w.INSTRUCTOR_ID = z.INSTRUCTOR_ID;
I dont know how to get inner query that would be something like INSTRUCTOR_ID.SECTION_ID = STUDENT_ID SECTION_ID,
Right now I am having in my query just returning all of the teachers who lived in that zipcode, but I also need to check for students that are taking a section that the instructors in that zip code are teaching....
SELECT DISTINCT FIRST_NAME,LAST_NAME,PHONE
FROM
(
SELECT FIRST_NAME,LAST_NAME,PHONE,ZIP
FROM STUDENT
)
Derived
WHERE ZIP IN (
SELECT ZIP
FROM STUDENT
INTERSECT
SELECT ZIP
FROM INSTRUCTOR
);