Link to home
Start Free TrialLog in
Avatar of nbotts
nbotts

asked on

Query for matching records across two tables where the time is within +/- 2 minutes

Hello,

I have two tables (TableA and TableB) of transaction logs that have fields of Name and DateTime respectively. Name and DateTime is the composite key. Table B provides a record of Transactions that occur related to TableA. I want to find out if there are any transactions in TableA that do not show-up in TableB.

The problem is that transactions recorded in Table B are often a minute or two (at most) different than what is recorded in Table A (but represent the same transaction). So I would like to create a query that 1) selects all transactions from TableA and TableB that match (where the DateTime field is within +/- 2 minutes of each other) and then 2) return all records from TableA that do not match from that set.

Another point is that some transactions for the Name and DateTime that occur in TableA could be within a minute of one another. So it would seem that some element of differentiating by which occurs first in terms of row (assuming use of rownum or something similar) would need to be addressed as well.

I've attached some sample data in which the goal would be to have the third record in Table A be returned because there is no match in TableB.

Thanks in advance for any assistance with this that can be provided!
matching-by-time-frame-query-dat.xlsx
Avatar of Anastasia D. Gavanas
Anastasia D. Gavanas
Flag of Greece image

Try using a cross tab query or an unmatched records query.
Avatar of nbotts
nbotts

ASKER

Thanks xtermie, technically the unmatched records query isn't the problem. After all that is provided in the query wizard.

It is more about how to do that given the situation I outlined.
ASKER CERTIFIED SOLUTION
Avatar of Jeffrey Coachman
Jeffrey Coachman
Flag of United States of America image

Link to home
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
Start Free Trial
Avatar of nbotts

ASKER

Thank you, that is what I was trying to put together. I guess I had never really experimented with pulling in the query similar to a table. I thought I always had to put together make table queries.

Much appreciated.