Modify SQL to use OUTER JOIN

bjv211
bjv211 used Ask the Experts™
on
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

Comment
Watch Question

Do more with

Expert Office
EXPERT OFFICE® is a registered trademark of EXPERTS EXCHANGE®
Commented:
Here's my untested attempt.  Note in the second LEFT JOIN line, F.[SchoolID] is an artifact from your original query.  Are you sure that's not supposed to be F.[FacultyID]?????
SELECT 
 C.CourseTitle,
 S.SemCode, 
 C.CourseID, 
 S.SectionNumber,
 D.SemDetails, 
 F.LastName, 
 F.FirstName,
 C.ID, 
 S.SectionID 
FROM
  ((((
  Courses as C
  INNER JOIN Sections ON C.[ID] = S.[CourseID])
  INNER JOIN Sems as D ON D.[SemCode] = S.[SemCode]) 
  LEFT JOIN CourseLoads as L ON S.[SectionID] = L.[SectionID])
  LEFT JOIN Faculty as F ON F.[SchoolID] = L.[FacultyID])
  
ORDER BY c.courseID, d.semcode, s.sectionnumber;

Open in new window

Author

Commented:
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

Commented:
glad to help

Do more with

Expert Office
Submit tech questions to Ask the Experts™ at any time to receive solutions, advice, and new ideas from leading industry professionals.

Start 7-Day Free Trial