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

DatabasesMySQL ServerColdFusion Language

Avatar of undefined
Last Comment
dqmq

8/22/2022 - Mon
ASKER CERTIFIED SOLUTION
dqmq

THIS SOLUTION ONLY AVAILABLE TO MEMBERS.
View this solution by signing up for a free trial.
Members can start a 7-Day free trial and enjoy unlimited access to the platform.
See Pricing Options
Start Free Trial
GET A PERSONALIZED SOLUTION
Ask your own question & get feedback from real experts
Find out why thousands trust the EE community with their toughest problems.
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

dqmq

glad to help
Experts Exchange has (a) saved my job multiple times, (b) saved me hours, days, and even weeks of work, and often (c) makes me look like a superhero! This place is MAGIC!
Walt Forbes