Want to protect your cyber security and still get fast solutions? Ask a secure question today.Go Premium

x
  • Status: Solved
  • Priority: Medium
  • Security: Public
  • Views: 513
  • Last Modified:

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?
1
kentgorrell
Asked:
kentgorrell
  • 2
1 Solution
 
fridomCommented:
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]); ....
0
 
kentgorrellAuthor Commented:
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.
0
 
VipulKadiaCommented:
Following is a MS-SQL query :
Select Customer_ID, MAX(Transaction_Date) FROM YourTable GROUP BY Customer_ID
0
 
fridomCommented:
Then you can use Dmax on the Transaction date or the MAX SQL function on the Transaction Date.
SELECT CustomerData.CustomerID, Max([LastModified]) AS LastDate
FROM CustomerData
Group by CustomerID;


Regards
0

Featured Post

Hire Technology Freelancers with Gigs

Work with freelancers specializing in everything from database administration to programming, who have proven themselves as experts in their field. Hire the best, collaborate easily, pay securely, and get projects done right.

  • 2
Tackle projects and never again get stuck behind a technical roadblock.
Join Now