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?
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?
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.
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
Select Customer_ID, MAX(Transaction_Date) FROM YourTable GROUP BY Customer_ID
ASKER CERTIFIED SOLUTION
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
if not do you have some autowert value field in the table? If yes just use e.g
DMax([autoIdField]); ....