Skip to content
Advertisement

Forcing NULL entries in ACCESS queries

I have two ACCESS tables as follows

I would like to know the total spent between two dates for Gold customers and set up the following query:

This gives me the following:

If I change the query to BETWEEN #2020/01/02# AND #2020/01/03# I get this:

Everything is fine so far. However, for the second query I would like to have the total transaction value for Gold customers as zero (or NULL) even if they have not spent anything during the period ie

I believe that I can do this in other dB’s using LEFT OUTER JOIN but this is not available in ACCESS. This post How do I write a full outer join query in access suggests using UNION. My attempt was

but this produced the following results:

This result contains all types of customer and has a duplicate for Customer 2. I’m sure the answer is obvious if you know how but I just don’t know how! All suggestions gratefully received – thanks!

Advertisement

Answer

If you want all Gold customers, then Customers should be the first table in the LEFT JOIN. There is also no need for a subquery on customers. However, MS Access does want one on Transactions:

User contributions licensed under: CC BY-SA
9 People found this is helpful
Advertisement