Unmatched in the last 30 days (1 Viewer)

Scott488

Registered User.
Local time
Today, 19:59
Joined
Nov 6, 2015
Messages
16
Hi all, there may be a simple solution to this, but it isn't leaping out at me this morning.

Two tables, customers and orders and I want to know who hasn't placed an order in the last 30 days.
 

arnelgp

..forever waiting... waiting for jellybean!
Local time
Tomorrow, 02:59
Joined
May 7, 2009
Messages
19,229
something like:

select customers.[customer id], customers.[customer name]
from
customers
where customers.[customer id] not in (select [customer id] from orders
where orders.[order date] >= date()-30)
 

isladogs

MVP / VIP
Local time
Today, 19:59
Joined
Jan 14, 2017
Messages
18,209
Use an unmatched query on both tables filtering for CustomerID Is Null in the Orders table AND OrderDate Between Date and Date-30.

Use the unmatched query wizard to make life simple
 

Pat Hartman

Super Moderator
Staff member
Local time
Today, 14:59
Joined
Feb 19, 2002
Messages
43,231
Although arne's solution will work, I don't like to use subqueries. Access doesn't optimize them well so they can be slow and they are hard to read in QBE view. Subqueries are fine if the BE is SQL Server but I still find them hard to read in QBE.

I would go with an unmatched query as Colin suggested but the problem with this is that Access will not return what you expect when you use a LEFT join and the criteria is on the RIGHT side table. Therefore, I create a query for the rightside table with criteria to limit the orders to the past 30 days and then use a left join of the customer to the query.
 

Users who are viewing this thread

Top Bottom