So I have the Following 2 tables in an access database
The first one that has information from when do we received emails and looks like this:
And the second table that has data from when we answer and looks like this:
What I want to do is to have them both joined to catch the next closest date that we answer the email, I have tried this
But it's not giving me the next date that the email was answered, can anybody help me with this?
The first one that has information from when do we received emails and looks like this:
from | received |
12 51 | 3/16/2023 2:49:56 PM |
12 51 | 3/16/2023 2:51:17 PM |
12 51 | 3/16/2023 2:51:57 PM |
12 51 | 3/16/2023 3:10:48 PM |
12 51 | 3/17/2023 3:23:01 PM |
12 51 | 3/17/2023 5:33:18 PM |
12 51 | 3/20/2023 6:23:31 PM |
And the second table that has data from when we answer and looks like this:
to | from |
12 51 | 3/17/2023 10:00:32 AM |
12 51 | 3/17/2023 3:35:15 PM |
12 51 | 3/20/2023 10:40:01 AM |
12 51 | 3/21/2023 8:47:02 AM |
What I want to do is to have them both joined to catch the next closest date that we answer the email, I have tried this
Code:
SELECT
RE.[From] AS ReceivedFrom,
SE.[To] AS SentTo,
SE.[Sent] AS SentDate,
RE.[Received] AS ReceivedDate
FROM
[Client Recieved Filtered data] AS RE
LEFT JOIN
(
SELECT DISTINCT
SE1.[To],
SE1.[Sent],
RE1.[From],
RE1.[Received],
(
SELECT TOP 1
ABS(DateDiff("s", SE2.[Sent], RE1.[Received]))
FROM
[sent email filtered data] AS SE2
WHERE
SE2.[To] = RE1.[From]
ORDER BY
ABS(DateDiff("s", SE2.[Sent], RE1.[Received]))
) AS MinTimeDiff
FROM
[sent email filtered data] AS SE1
INNER JOIN
[Client Recieved Filtered data] AS RE1
ON
SE1.[To] = RE1.[From]
) AS SE
ON
RE.[From] = SE.[From]
AND ABS(DateDiff("s", SE.[Sent], RE.[Received])) = SE.MinTimeDiff;
But it's not giving me the next date that the email was answered, can anybody help me with this?