Display a list of Oldest Orders for each Customer

Mase5701

New Member
Joined
Dec 19, 2018
Messages
6
I'm trying to create a list of all the oldest orders my customer has. but I can't seem to get my subquery to list one record for each CustomerID. Whenever I add the Order Amount to the subquery every orders lists.

I have these tables
tblCustomers - Customer ID, Customer Name, etc.
tblCustomerOrders - OrderID, OrderDate, OrderAmount

I want a list that has Customer ID, DateOfOldestOrder, Amount


first query [qryCustomerOrdersOldest]

SELECT tblCustomerOrders.CustomerID, Min(tblCustomerOrders.OrderDate) AS MinOfOrderDate
FROM tblCustomerOrders
GROUP BY tblCustomerOrders.CustomerID;


subquery



SELECT tblCustomerOrders.OrderAmount, qryCustomerOrdersOldest.CustomerID, Min(qryCustomerOrdersOldest.MinOfOrderDate) AS MinOfMinOfOrderDate
FROM qryCustomerOrdersOldest LEFT JOIN tblCustomerOrders ON qryCustomerOrdersOldest.CustomerID = tblCustomerOrders.CustomerID
GROUP BY tblCustomerOrders.OrderAmount, qryCustomerOrdersOldest.CustomerID;
 

Excel Facts

What is the last column in Excel?
Excel columns run from A to Z, AA to AZ, AAA to XFD. The last column is XFD.
It will as you are grouping on that as well.
Make it a where > 0 instead
 
Upvote 0
You do not need group by in the main query.?
You have identified a record in the first query that hopefully has the minimum date.? What happens if there are more than one order on that date.?
I'd probably look at the min ID as well.
Then use that in the main query.?

So identify ID for min date for each customer. Then use that ID for the main query and pull out whatever fields you want then.
 
Upvote 0

Forum statistics

Threads
1,223,565
Messages
6,173,089
Members
452,501
Latest member
musallam

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