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


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!
Who is Participating?
Jeffrey CoachmanConnect With a Mentor MIS LiasonCommented:
Try this...
Open the two tables for viewing, then run Query1
Try using a cross tab query or an unmatched records query.
nbottsAuthor Commented:
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.
nbottsAuthor Commented:
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.
Question has a verified solution.

Are you are experiencing a similar issue? Get a personalized answer when you ask a related question.

Have a better answer? Share it in a comment.

All Courses

From novice to tech pro — start learning today.