This is the table structure (the relevant bits):

I’m trying to find the contactLog entries that match the declarations on clientID and the date of the declaration (within 8 hours actually). Here’s what I came up with:
SELECT
D.ClientID
D.DeclarationID
CL.ContactDescription,
CL.ContactDate,
FROM Declarations D
INNER JOIN (Contacts C
INNER JOIN (PartialContacts PC
INNER JOIN ContactLogs CL
ON PC.ContactPartID = CL.ContactPartID )
on PC.ContactID = C.ContactID
)
ON C.ClientID = D.ClientID AND DATEDIFF(hour, D.DeclarationDate, CL.ContactDate) < 8
However, the join is not functioning properly, because I get non matching dates back for the CL.ContactDate and it’s clear that it’s just return every row in CL for that patient ID. I think… I’m not really sure what is going wrong.

Thanks to Damien:
I did not specify a lower limit for datediff, so the matching did not work properly. Apperently, the joins are just fine: