MS Query Compare Two Tables with Date fields

almostanexpert

Board Regular
Joined
Apr 20, 2007
Messages
86
Hello All,

Thank you for taking an interest in this post.

I would like to compare two date fields in two different tables in MS Query to return records that meet this criteria table1.DateTime <= table.ExpireDate. Can this be achieved in MS Query?

I have tried a JOIN

table1 t1
JOIN table2 t2 ON
t1.DateTime <= t2 ExpireDate

However my data is duplicating.

Any information is greatly appreciated.

Thank you
 

Excel Facts

Control Word Wrap
Press Alt+Enter to move to a new row in a cell. Lets you control where the words wrap.
Hello,

You have to join tables with common fields and then create your condition "t1.DateTime <= t2 ExpireDate". SQL query should have structure like this:

SELECT
t1.field_1,
t1.field_2,
...
t1.field_n,
t2.field_1,
...
t2.field_n
FROM table1 t1 LEFT OUTER JOIN table2 t2 ON t1.[Unique Items Field]=t2.[Related Field]
WHERE t1.DateTime<=t2.ExpireDate
 
Last edited:
Upvote 0
It does not have to be left or right join. You can create inner join like you did, but not with DateTime and ExpireDate fields. You must use some kind of "identification field" to join two tables and then set condition you want in Where clause: t1.DateTime<=t2.ExpireDate.
If you can send some example of two tables, I will show you what I meant.
 
Upvote 0
After some pondering I scrapped this attempt and restarted my query using the graphical interface. There I found my Joining options amoung them the <= options I was looking for. Thanks for helping me get the head in gear.

Best Regards
 
Last edited:
Upvote 0

Forum statistics

Threads
1,215,083
Messages
6,123,020
Members
449,092
Latest member
ikke

We've detected that you are using an adblocker.

We have a great community of people providing Excel help here, but the hosting costs are enormous. You can help keep this site running by allowing ads on MrExcel.com.
Allow Ads at MrExcel

Which adblocker are you using?

Disable AdBlock

Follow these easy steps to disable AdBlock

1)Click on the icon in the browser’s toolbar.
2)Click on the icon in the browser’s toolbar.
2)Click on the "Pause on this site" option.
Go back

Disable AdBlock Plus

Follow these easy steps to disable AdBlock Plus

1)Click on the icon in the browser’s toolbar.
2)Click on the toggle to disable it for "mrexcel.com".
Go back

Disable uBlock Origin

Follow these easy steps to disable uBlock Origin

1)Click on the icon in the browser’s toolbar.
2)Click on the "Power" button.
3)Click on the "Refresh" button.
Go back

Disable uBlock

Follow these easy steps to disable uBlock

1)Click on the icon in the browser’s toolbar.
2)Click on the "Power" button.
3)Click on the "Refresh" button.
Go back
Back
Top