Tek-Tips is the largest IT community on the Internet today!

Members share and learn making Tek-Tips Forums the best source of peer-reviewed technical information on the Internet!

  • Congratulations SkipVought on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

SQL: Left Join does not show all Records from Table A!

Status
Not open for further replies.

waldemar

Programmer
Nov 15, 2001
245
0
0
DE
Well, I understand that a left join should show all records from table A and only those records in table B that match.

Well, it doesnt work in my case. This is query before (A):

SELECT *
FROM ((tblStudents LEFT JOIN tblStudentsBus ON tblStudents.strStudentID = tblStudentsBus.strStudentID) LEFT JOIN tblStudentsMedical ON tblStudents.strStudentID = tblStudentsMedical.strStudentID) LEFT JOIN tblUserStudentsSelection ON tblStudents.strStudentID = tblUserStudentsSelection.strStudentID
WHERE (((tblStudents.dtmEntryDate)<=[Forms]![frmToDo]![gdtmVirtualDate]) AND ((tblStudents.dtmLeavingDate)>[Forms]![frmToDo]![gdtmVirtualDate] Or (tblStudents.dtmLeavingDate) Is Null) AND ((tblUserStudentsSelection.strUserID)=[application].[currentuser]));

and this after (B):

SELECT *
FROM (((tblStudents LEFT JOIN tblStudentsBus ON tblStudents.strStudentID = tblStudentsBus.strStudentID) LEFT JOIN tblStudentsMedical ON tblStudents.strStudentID = tblStudentsMedical.strStudentID) LEFT JOIN tblUserStudentsSelection ON tblStudents.strStudentID = tblUserStudentsSelection.strStudentID) LEFT JOIN tblStudentsClasses ON tblStudents.strStudentID = tblStudentsClasses.strStudentID
WHERE (((tblStudents.dtmEntryDate)<=[Forms]![frmToDo]![gdtmVirtualDate]) AND ((tblStudents.dtmLeavingDate)>[Forms]![frmToDo]![gdtmVirtualDate] Or (tblStudents.dtmLeavingDate) Is Null) AND ((tblUserStudentsSelection.strUserID)=[application].[currentuser]) AND ((tblStudentsClasses.strClassID) Like &quot;*&quot; & [Forms]![frmToDo]![txtCurrentSchoolyear] & &quot;*&quot;));

Some explanation: Query A is supposed to pick all parents that have students in the school at a current date ([Forms]![frmToDo]![gdtmVirtualDate]). The rest are mostly 1:1 tables with additional data. This wirks fine in Query A.

In Query B I tried to attach [tblStudentsClasses], a list of all classes the student attends. Query B is supposed to show the same as Query A + the Current Class (comparing [Forms]![frmToDo]![txtCurrentSchoolyear] - the schoolyear is hidden in the [strClassID])... so it should have the same number of records as Query A ...

... although this is a left Join, Query B SKIPPS all Students that do not have a current Schoolyear-Class assigned. I read in some threads Access is supposed to fill those records with NULL Fields (when they don't exist). Here this is not happening - the record is simply skipped. Anybody has a clue why this is happening?
 
Access does fill the records that are not matched with NULL, however in your WHERE clause you have the following condition: ((tblStudentsClasses.strClassID) Like &quot;*&quot; & [Forms]![frmToDo]![txtCurrentSchoolyear] & &quot;*&quot;)).

This condition eliminates all NULL records. This is the problem.
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top