I'm trying to create a SQL QUERY where it shows the latest or no "DateOfSpecimenCollection" of a record in a table. Below i have two table called "Swab" and "ContactTracingHeader".
SELECT CTH.AutoID, CTH.Firstname, CTH.Lastname, SW.DateOfSpecimenCollection
FROM ContactTracingHeader AS CTH LEFT JOIN Swab AS SW ON CTH.AutoID = SW.PatientNo
WHERE SW.DateOfSpecimenCollection = (SELECT FIRST(DateOfSpecimenCollection)
FROM Swab ORDER BY DateOfSpecimenCollection ASC);
What I'm trying to output is when a user in "Swab" table inputs multiple and the same "PatientNo." it will only show one record of "PatientNo" with the latest "DateOfSpecimenCollection" And its "Firstname" and "Lastname", And also output record of some Patient in "ContactTracingHeader" Table that doesn't have "DateOfSpecimenCollection" to "Swab" table, this is also the reason why i used the LEFT JOIN. I apologize as I'm beginner in SQL MS ACCESS and also for bad explanation because of my bad english and duplicate question. Thank you in advance!
This is the visual Representation of the SQL:
Table ContactTracingHeader:
|AutoID|Firstname|Lastname|
1 John Smith
2 Felix James
Table Swab:
|PatientNo|DateOfSpecimenCollection|
1 07/21/2020
1 07/22/2020
1 08/01/2020
The query output that i'm trying to make:
|AutoID|Firstname|Lastname|DateOfSpecimenCollection|
1 John Smith 08/01/2020
2 Felix James (Blank)
since "Felix James" don't have any record in Table swab, his "DateOfSpecimenCollection" is blank or nothing.