Access 2007 Query to show all master records even when no activity

I have a basic query with 2 tables.

Table A
Name | Description

Table B
Name | Date | Quantity

I need a list of all descriptions in Table A with a Total Quantity from Table B

What I get is a list of all records from Table A that have activity in Table B, but I need to see ALL records in Table A and just assign a 0 to the ones that don't have anything in table B.

I have a right join on Name, so that's not the issue, any ideas how I can get all records from Table A?
wlreimerAsked:
Who is Participating?
I wear a lot of hats...

"The solutions and answers provided on Experts Exchange have been extremely helpful to me over the last few years. I wear a lot of hats - Developer, Database Administrator, Help Desk, etc., so I know a lot of things but not a lot about one thing. Experts Exchange gives me answers from people who do know a lot about one thing, in a easy to use platform." -Todd S.

DoveTailsCommented:
Something like this ?
SELECT TableA.Description,
       TableA.Name2,
       Sum(TableB.Quantity) AS SumOfQuantity
  FROM TableA
  LEFT JOIN TableB
    ON TableA.Name2 = TableB.Name2
 GROUP BY TableA.Description, TableA.Name2;

Open in new window


note: "name" is a reserved word, so using "name2".
0
Helen FeddemaCommented:
I made several queries -- a Totals query to add up the quantities, one showing clients with purchases, and one showing those without purchases, and a union query to join them.

BTW, if you really have fields called Name and Date, that is not a good idea, since they are reserved names.  Also, it is best to join on a unique ID, such as an AutoNumber ClientID field (but I used ClientName in case you have to work with that field).

Here is a screen shot of the queries:
QueriesQueries.accdb
0
wlreimerAuthor Commented:
I wish it was that easy.  I have done exactly that and I still just get the records with activity.  Any other ideas?
0
Ultimate Tool Kit for Technology Solution Provider

Broken down into practical pointers and step-by-step instructions, the IT Service Excellence Tool Kit delivers expert advice for technology solution providers. Get your free copy now.

Helen FeddemaCommented:
Here is the union query showing the final results:
Final results
0

Experts Exchange Solution brought to you by

Your issues matter to us.

Facing a tech roadblock? Get the help and guidance you need from experienced professionals who care. Ask your question anytime, anywhere, with no hassle.

Start your 7-day free trial
Helen FeddemaCommented:
Did you try mine?  It is more complicated, but does include the clients with no purchases.
0
DoveTailsCommented:
Huh?.... seems the query shows all values from Table A in my example.  I must be misunderstanding something.
Couple things to consider ... are there any 'rules' for data on your tables ?
Maybe the IIF function can be useful;
    iif ( condition, value_if_true, value_if_false )

I'll attach the test db if you care to look at the results I'm seeing ... you have me curious.

I see where Helen is going with the Union query ... wondering if a straightforward join will work.
0
Gustav BrockCIOCommented:
It is much simpler. Just use Nz() and one query:

SELECT
    [TableA].[Name],
    Nz(Sum([TableB]![Quantity]), 0) AS TotalQuantity
FROM
    TableA
LEFT JOIN
    TableB ON
        [TableA].[Name] = [TableB].[Name]
GROUP BY
    [TableA].[Name];

/gustav
0
wlreimerAuthor Commented:
Thanks for the help everyone.  The Nz didn't work and just adjusting the join wouldn't do it.

I ended up doing the union query to make it work.
0
It's more than this solution.Get answers and train to solve all your tech problems - anytime, anywhere.Try it for free Edge Out The Competitionfor your dream job with proven skills and certifications.Get started today Stand Outas the employee with proven skills.Start learning today for free Move Your Career Forwardwith certification training in the latest technologies.Start your trial today
Microsoft Access

From novice to tech pro — start learning today.

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.