Link to home
Create AccountLog in
Avatar of bjv211
bjv211

asked on

Modify SQL to use OUTER JOIN

Using CF to connect to Access 2007 DB, but this is more of a SQL question.

I have a table courseloads (facultyID, sectionID, clID) which keeps track of who's teaching what section. so if a professor is teaching a section their facultyID and the sectionID are put in the table

I want to run a query to produce all the sections offered including those without assigned professors.  

I need to modify the attached SQL to show ALL sections including those not listed in the table 'courseloads'.  As of now it only shows records that appear in courseloads and sections.  I believe I need an outer join but don't know how to implement.
SELECT Courses.CourseTitle, Sections.SemCode, Courses.CourseID, Sections.SectionNumber, Sems.SemDetails, Faculty.LastName, Faculty.FirstName, Courses.ID, Sections.SectionID
FROM (Sems INNER JOIN (Courses INNER JOIN Sections ON Courses.[ID] = Sections.[CourseID]) ON Sems.[SemCode] = Sections.[SemCode]) INNER JOIN (Faculty INNER JOIN CourseLoads ON Faculty.[schoolID] = CourseLoads.[FacultyID]) ON Sections.[SectionID] = CourseLoads.[SectionID]
ORDER BY courses.courseID, sems.semcode, sections.sectionnumber;

Open in new window

ASKER CERTIFIED SOLUTION
Avatar of dqmq
dqmq
Flag of United States of America image

Link to home
membership
Create an account to see this answer
Signing up is free. No credit card required.
Create Account
Avatar of bjv211
bjv211

ASKER

Had to tweek it just a bit, but it works beautifully now.  THANK YOU!!
SELECT  C.CourseTitle, D.SemCode,  C.CourseID,  S.SectionNumber, D.SemDetails,  F.LastName,  F.FirstName, C.ID,  S.SectionID 
FROM  ((((Courses C INNER JOIN Sections S ON C.[ID] = S.[CourseID]) INNER JOIN Sems D ON D.[SemCode] = S.[SemCode])  LEFT JOIN CourseLoads L ON S.[SectionID] = L.[SectionID]) LEFT JOIN Faculty F ON F.[schoolID] = L.[FacultyID])
ORDER BY C.courseID, D.semcode, S.sectionnumber;

Open in new window

glad to help