Link to home
Start Free TrialLog in
Avatar of kentgorrell
kentgorrell

asked on

Access query to return a list of customers (Distict) with their most recent transaction date

I need to contruct a query that returns just one record for each customer (that has made a purchase) with the date of their last purchase.

So I have a transaction table with the customer ID so from this table I need to return just the most recent instance of each Customer ID along with the transaction date. I'll then join this to the customer table to get names and stuff.

The query is used for a report which then filters the date range of the transactions.

What is the fastest method to return this data set?
Avatar of F. Dominicus
F. Dominicus
Flag of Germany image

Well the best is to keep some date with the  entries. Have you done that?

if not do you have some autowert value field in the table? If yes just use  e.g
DMax([autoIdField]); ....
Avatar of kentgorrell
kentgorrell

ASKER

As I said, the Transaction table has Customer_ID and Transaction_Date.

To clarify, I want a list that includes just one record for each customer - the most recent.

of course if I don't include the date then SELECT DISTINCT will work but I do need the date and it must be the most recent.

I can work the join to the customer table out myself I just need the SQL for the Transation Table to return just the most recent record for each customer.
Following is a MS-SQL query :
Select Customer_ID, MAX(Transaction_Date) FROM YourTable GROUP BY Customer_ID
ASKER CERTIFIED SOLUTION
Avatar of F. Dominicus
F. Dominicus
Flag of Germany image

Link to home
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
Start Free Trial