Using the First or Min function.

Mase5701

New Member
Joined
Dec 19, 2018
Messages
6
I have a table with all my Customer Orders and I'm trying to return a single record for the Earliest OrderPlaced but I cannot for the life of me return the single oldest Order Number according to the CustomerID.

I have 2 tables:
CustomerOrders Customers
OrderNumber (pk) CustomerID (pk)
OrderDate
OrderAmount*

I have 2 queries as such:

SELECT tblCustomers.CustomerID, Min(tblCustomerOrders.OrderDate) AS MinOfOrderDate
FROM tblCustomers INNER JOIN tblCustomerOrders ON tblCustomers.CustomerID = tblCustomerOrders.CustomerID
GROUP BY tblCustomers.CustomerID;


SELECT tblCustomerOrders.OrderNumber, tblCustomerOrders.OrderAmount, qryCustomerOrderMinDate.MinOfOrderDate
FROM qryCustomerOrdersMinDate LEFT JOIN tblCustomerOrders ON qryCustomerOrdersMinDate.CustomerID = tblCustomerOrders.CustomerID;

my subquery shows every record in the CustomerOrders table. I just want one record for each Customer #.




Am I stupid? This seems like such a simple issue but I've been stuck on it forver!
 

Excel Facts

Copy formula down without changing references
If you have =SUM(F2:F49) in F50; type Alt+' in F51 to copy =SUM(F2:F49) to F51, leaving the formula in edit mode. Change SUM to COUNT.
Welcome to the Board!

In your second query, you need to join on 2 fields, the CustomerID and the Date fields.
Otherwise, you really aren't selecting the single, minimum record for each Customer ID.
 
Last edited:
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