Skip to content
Advertisement

how to get a record based on max date for each user in different multiple tables

I’m trying to make a query that can select the names, DateOfSpecimenResult,SwabResult,DateOfReleaseOfResult. Heres the Visual Representation:

Table: ContactTracingHeader

Table: Swab

Note: ContactTracingHeader.AutoID = Swab.PatientNo

Table: SwabResult

Query Output that I’m trying to make

Note: Swab.ResultID = SwabResult.AutoID

Here, I’m only trying to show a Name with the latest DateOfSpecimenCollection and then use it as a reference for the 2 other column which is SwabResult and DateOfReleaseOfResult, And Since “Chris” doesn’t have a input on the Swab table, his records are blank but his name and AutoID Still appears on the table. The SwabResult shows the NEGATIVE, or POSITIVE depending on the ID from table Swab.

What i have done so far is this:

This Query gets the latest DateOfSpecimenCollection and Output those who aren’t in the Swab table which is correct, however it duplicates the record depending how many SwabResult or DateOfReleaseOfResult it has. Also I tried INNER JOIN the table SwabResult so i can output the SwabResult instead of the ID, However it gave me JOIN Expression not supported Error.

I apologize for the long and confusing explanation and duplicate question as I’m trying to strugge to find some answers on the internet. Thank you!

Advertisement

Answer

Need a unique identifier in Swab table. If not already there, autonumber should serve

Consider:

Query1:

Query2

Or this sequence:

Query1:

Query2:

Query3:

User contributions licensed under: CC BY-SA
2 People found this is helpful
Advertisement