I have three tables which I want to combine into one view or temporary table, they are a pupil table:
| id | UPN |
A snapshot table:
| id | PupilID | Surname | Forename | AssessmentYr |
A results table:
| id | PupilID | KS1RdTA | KS1WrTA |
The id in the pupil table matches with PupilID in the snapshot and results, in the snapshot table there may be more than one entry with the same PupilID.
There may not be any match in either the pupil or results table.
My question is how to write a query which will take every entry in the snapshot table, regardless of whether it is matched with anything in the pupil or results table, but, where possible, match it up.
I want to either make this into a temporary table or a view for subsequent manipulation and would welcome some suggestions on which would work best.
Thanks in advance for your help.
You did not specify if the
resultstable may be missing rows for some records in thepupiltable, but I believe this is what you’re looking for:If I am misunderstanding, and it is related rows from the
pupiltable which may be missing fromsnapshot(that is, a NULLPupilIDinsnapshot, then this may be the correct query, using a differentLEFT JOINwhich preferssnapshotoverpupil.