Kayleigh
Member
- Local time
- Today, 09:28
- Joined
- Sep 24, 2020
- Messages
- 709
I'm having trouble writing a query to display all items which are NOT existing in related table. But when there are multiple items related to key, it shows each item multiple times in query. I know this is probably to do with the join but since can't find any way to join the lookup table to main table in query. Perhaps someone can help.
The first query finds items related to key field and displays appropriate text in Type field:
Next query, finds all items not matched to the results of above query. Here I am finding duplicated results where the key field has more than one entry.
Here are the results of the first and second queries:
The first query finds items related to key field and displays appropriate text in Type field:
SQL:
SELECT tblIncidentLogDetails.fldIncidentLogDetailsID, jtblIncidentLogStudent.fldIncidentLogStudentID, jtblIncidentLogStudent.fldStudentID, tblIncidentLogDetails.fldTypeMed, tblIncidentLogDetails.fldTypeSG, tblIncidentLogDetails.fldTypeBe, tblIncidentLogDetails.fldTypeGen, IIf([tblIncidentLogDetails]![fldTypeMed]=True,"Medical",(IIf([tblIncidentLogDetails]![fldTypeSG]=True,"Safeguarding",(IIf([tblIncidentLogDetails]![fldTypeBe]=True,"Behaviour",(IIf([tblIncidentLogDetails]![fldTypeGen]=True,"General",Null))))))) AS Type
FROM jtblIncidentLogStudent INNER JOIN tblIncidentLogDetails ON jtblIncidentLogStudent.fldIncidentLogStudentID = tblIncidentLogDetails.fldIncidentLogStudentID;
Next query, finds all items not matched to the results of above query. Here I am finding duplicated results where the key field has more than one entry.
SQL:
SELECT DISTINCT lkptblIForms.fldICaptionName, qryIncidentStudentType.fldIncidentLogStudentID, qryIncidentStudentType.Type
FROM qryIncidentStudentType, lkptblIForms
WHERE (((lkptblIForms.fldICaptionName)<>[qryIncidentStudentType]![Type]) AND ((qryIncidentStudentType.Type) Is Not Null))
ORDER BY qryIncidentStudentType.fldIncidentLogStudentID;
Here are the results of the first and second queries: