I have two tables that I need to compare and find the records that do not match. I thought I had this working but it seems to be buggy, or I'm not doing it right. 😕
The grade_import table is from a csv file that has student grades.
The students table is all my active students broken up in 1st year thru 4th year students.
There are about 415 total students.
I need to match on Student_ID from the import table to UID in the student table and if some don't matches then I cannot write to the grades table.
Like so...
SELECT * FROM ".$prefix."_tl_students a
LEFT JOIN ".$prefix."_tl_session_grade_import b ON a.UID = b.Student_ID
WHERE b.Session_ID = '$Session_ID'
AND a.UID IS NULL
From my understanding if I only need to look at the records I have in the import table then should I switch these two tables around (reverse them) and do the LEFT JOIN on the import table?
SELECT * FROM ".$prefix."_tl_session_grade_import a
LEFT JOIN ".$prefix."_tl_students b ON b.UID = a.Student_ID
WHERE a.Session_ID = '$Session_ID'
AND b.UID IS NULL
Would I then pull all the a.Student_ID's and any b.UID that do not match would be NULL.
Did I get this right?