This is an example similar to what you might do
SELECT tblARCustomer.strCustomerI
FROM tblOEOrder RIGHT JOIN tblARCustomer ON tblOEOrder.strCustomerID = tblARCustomer.strCustomerI
GROUP BY tblARCustomer.strCustomerI
Main Topics
Browse All TopicsI have a two tables like so:
Table1: CustInfo
CustID - Primary Key
Name
Table2: OrderInfo
OrderNumber - Primary Key
Date
Amount
CustID
I want to sum all the amounts from the orderinfo grouped by custID which I can do just fine. What I am having a problem with is showing ALL custID's even if there are no amounts or orders for them. I have the relationship set up to show all custid's and only those with matches in orderinfo but it doesn't work.
Please help.
J_K_M_A_N
This Question has been solved and asker verified All Experts Exchange premium technology solutions are available to subscription members.
Experts Exchange has been collecting answers to technology questions since 1996…3 million and counting! If you have a question, chances are we already have your answer.
If you can't find the exact answer you're looking for, ask our exclusive community of 50,000 experts. You’ll get a personalized answer from a trusted professional.
Thousands of free tech tips, tricks, how-to’s and tutorials are available in our peer reviewed articles section. See for yourself how smart our experts are, no login required.
Access the answers to your technology questions today.
30-day free trial. Register in 60 seconds.
Members of the expert community talk about why the experience at Experts Exchange is different than what you will find anywhere else.

Try it out and discover for yourself.
30-day free trial. Register in 60 seconds.
Join the community of experts here and help other tech pros by answering question in your area of expertise. You can earn FREE access to all Experts Exchange's premium features and resources.
At the risk of being told that my table SUCKS (which I have already been told) here is my SQL statement.
SELECT Child.Name, (Sum([10A50]+[10A100]+[10A
FROM Child LEFT JOIN Orders ON Child.ChildID = Orders.ChildID
WHERE (((Orders.Date) Between #3/1/2006# And #3/24/2006#))
GROUP BY Child.Name
ORDER BY Child.Name;
And it does NOT return all 57 names in the Child table. I am not sure why. Maybe because of the sums I am doing? I don't know. I am guessing it is beacuse of the WHERE with the dates. I am guessing it doesn't like that. Is there a way around it?
J_K_M_A_N
Maybe I'm missing something, but if some of the Child.Names do not have any orders and you use date criteria in the WHERE clause, how can you expect to see them, unless you include the IsNull() criterion? Are you saying there are more than 2 Names missing? Can you give us an example of what is missing? I just noticed you use the word Date as a field - that is a no-no as Date is an Access Reserved Word. If you absolutely have to use it, it must be wrapped in square brackets.
Orders.[Date]
Well, the orders table holds all the data for the past year+. I want to show all customers and the totals of a certain month. I was hoping to do that with one SQL statement. It looks like I will not be able to do that. Some of the customers have data in the table but not that are between the dates I put in. I would like to see all of their totals (even if they are 0) for all customers. Does that explain it better?
J_K_M_A_N
OK, the two customers that were added were the only two missing or were there more? Try this query. I have included a parameters criteria which includes the year as you said the table contains all the data for the past year+. You should also qualify all the fields in the sum() functions with their table name:
SELECT Child.Name, (Sum([10A50]+[10A100]+[10A
FROM Child LEFT JOIN Orders ON Child.ChildID = Orders.ChildID
WHERE Format(Orders.[Date],"yym"
GROUP BY Child.Name
ORDER BY Child.Name;
Let me give you some sample data:
Table Orders:
Date ChildID 10A50 10A100 10A250 10A500 10A1000 Value (There is more but this will do for an example)
02/25/2006 2 100 200 0 0 0 $3400
02/18/2006 3 50 300 0 0 0 $1700
03/27/2006 2 50 100 0 0 0 $2300
03/15/2006 1 50 0 250 500 0 $2700
03/18/2006 2 50 100 0 0 1000 $3500
Now what I want is a list like the one below using the query where I can tell it what dates I want. In this case, I want all of March 2006 so I would like to see something like this:
ChildID 10A50 10A100 10A250 10A500 10A1000 Value
1 50 0 250 500 0 $2700
2 100 200 0 0 1000 $5800
3 0 0 0 0 0 $0
ChildID 3 would be zero because that sale was in Feburary. ChildID 1 and 2 would sum the fields together but only for the month of march. Is there a way to do that?
J_K_M_A_N
If it is a case of seeing zeros instead of a blank, try:
SELECT Child.Name,
Nz(Sum([10A50]+[10A100]+[1
Nz(Sum([25A50]+[25A100]+[2
Nz(Sum([32A50]+[32A100]+[3
Nz(Sum([38A50]+[38A100]+[3
Nz(Sum([50A50]+[50A100]+[5
Format(Nz(Sum(Orders.Value
FROM Child LEFT JOIN Orders ON Child.ChildID = Orders.ChildID
WHERE Format(Orders.[Date],"yym"
GROUP BY Child.Name
ORDER BY Child.Name;
The blank would be fine but I don't get that. Not for ALL of the customers. I am going to give out the points and give up. I really don't know what I am doing and I need to find a good book on the subject. I have the program written without using a database and it works ok. I will just stick with that and stop trying to learn database programming for now. It is driving me crazy. Thanks for all of your attempts.
J_K_M_A_N
Business Accounts
Answer for Membership
by: jimhornPosted on 2006-03-28 at 08:30:31ID: 16312002
Select blah blah blah
FROM CustInfo
LEFT JOIN OrderInfo ON CustInfo.blah = OrderInfo.blah
The left join guarantees that all records in CustInfo are returned, even if there's no related OrderInfo records.
Hope this helps.
-Jim