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

Wildcard in VLOOKUP
Use =VLOOKUP("Apple*" to find apple, Apple, or applesauce

Joe4

MrExcel MVP, Junior Admin
Joined
Aug 1, 2002
Messages
56,997
Office Version
  1. 365
Platform
  1. Windows
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:

Watch MrExcel Video

Forum statistics

Threads
1,130,088
Messages
5,640,041
Members
417,124
Latest member
Herostrata

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
Top