I have a query that displays the modules that are available for a student to enrol on and shows them in a list.. I would like it if the modules that student has enrolled on do not show in the list. Once a student has enrolled on a module it is stored in a table called tbl_studentModule which has two fields, regNum ($studentID) and moduleID.
What do I need to add to this query to only show the modules that are not already in the tbl_studentModule with the relevant regNum.
EG I would lik the query to say something to the effect where the combination of regNum and moduleID do not already exist if tbl_studentModule.
Here is what I have so far…
SELECT DISTINCT am.moduleID, m.moduleName, am.type, s.regNum, s.award
FROM tbl_awardModules am
LEFT OUTER JOIN tbl_module m ON am.moduleID = m.moduleID
INNER JOIN tbl_awardLevels al ON am.awardLevelID = al.awardLevelID
INNER JOIN tbl_award a ON al.awardID = a.awardID
INNER JOIN tbl_student s ON a.awardID = s.award
LEFT JOIN tbl_studentModules sm ON s.regNum = sm.regNum
WHERE am.type <> 'C' AND sm.regNum = '$student_id' AND m.moduleName <> 'A_null_Choice' AND m.moduleName NOT LIKE '%Not Running%'
Hope that makes sense…
Ok, I sussed it..
I added
to the end if the query so now it only shows the rows of the table that do not already contain that combination of values