Here's a simple example of how LEFT JOINs work
Code:
tblStaffNames
StaffKey PK
StaffName Text
tblStaffsKids
KidKey PK
KidName Text
KidParent FK to tlbStaffNames
DATA in tblStaffNames
1 George Hamilton
2 Linda Smith
3 Babe Ruth
4 Ernest Borgnine
5 Jane Doe
DATA in tblStaffsKids
100 Jamie 2
101 Kate 2
102 Whoopi 1
104 Ernie 4
This shows the results from a standard INNER JOIN, which only returns records that exist in both tables.
Code:
SELECT StaffKey, StaffName, KidKey, Kidname
FROM tblStaffnames INNER JOIN tblStaffkids ON StaffKey = KidParent
StaffKey StaffName KidKey KidName
1 George Hamilton 102 Whoopi
2 Linda Smith 100 Jamie
2 Linda Smith 101 Kate
4 Ernest Borgnine 104 Ernie
This shows the LEFT JOIN keeping all records in the left table, and returning a NULL record if there is no matching record in the right table.
Code:
SELECT StaffKey, StaffName, KidKey, Kidname
FROM tblStaffnames LEFT JOIN tblStaffkids ON StaffKey = KidParent
StaffKey StaffName KidKey KidName
1 George Hamilton 102 Whoopi
2 Linda Smith 100 Jamie
2 Linda Smith 101 Kate
3 Babe Ruth (-) (-)
4 Ernest Borgnine 104 Ernie
5 Jane Doe (-) (-)
This shows the NZ overriding the NULL values.
Code:
SELECT StaffKey, StaffName, NZ(KidKey,0) AS KidKey, NZ(Kidname,"(none)") AS KidName
FROM tblStaffnames LEFT JOIN tblStaffkids ON StaffKey = KidParent
StaffKey StaffName KidKey KidName
1 George Hamilton 102 Whoopi
2 Linda Smith 100 Jamie
2 Linda Smith 101 Kate
3 Babe Ruth 0 (none)
4 Ernest Borgnine 104 Ernie
5 Jane Doe 0 (none)