Microsoft Access LEFT JOIN: Return the Latest Transaction per Customer
Question details
Return every customer and the highest transaction number associated with that customer.

- Product
- Microsoft Access
- Device & OS
- not provided
- Scenario
- A customer table must be joined to transactions while returning only the highest transaction number for each customer.
- Observed behavior
- The desired result includes one row per customer, with a blank transaction number when the customer has no transactions.
Check that tblCust.ID matches tblTrans.CustID and that TransNr identifies the latest transaction by its highest value. If your table or field names differ, substitute them in the query.
Join customers to a grouped transaction subquery
Use this query to find the maximum transaction number per customer while retaining customers without transactions.
The subquery groups transactions by CustID and calculates Max(TransNr). The LEFT JOIN then matches those results to every row in tblCust.
Open the database in Microsoft Access, select Create > Query Design, and switch to SQL View.
Replace the SQL in the editor with: SELECT tblCust.CustName, Q.TransNr FROM tblCust LEFT JOIN (SELECT tblTrans.CustID, Max(tblTrans.TransNr) AS TransNr FROM tblTrans GROUP BY tblTrans.CustID) AS Q ON tblCust.ID = Q.CustID;
Select Run on the query ribbon. Check that each customer appears with the highest transaction number, or a blank value if no transaction exists.

Review customer and transaction data in WPS Spreadsheets
WPS Office is a free, lightweight alternative with a familiar interface for working with Office files. Open exported customer and transaction data in WPS Spreadsheets for review; it does not run Access database queries or replace the LEFT JOIN.

Frequently Asked Questions
Why does the query use a LEFT JOIN?
The LEFT JOIN keeps all rows from tblCust, including customers with no matching CustID in tblTrans. Their TransNr value is Null.
Does Max(TransNr) always return the most recent transaction?
Only if the highest transaction number represents the latest transaction. If recency depends on a transaction date, the query needs to use that date instead.
Can this query return other fields from the latest transaction?
The example returns only CustName and the maximum TransNr. To retrieve other transaction fields, join the grouped result back to tblTrans using both CustID and TransNr; handle ties if those fields do not uniquely identify a row.
Where do I paste the SQL in Access?
In the database, select Create > Query Design, switch to SQL View, and paste the query into the SQL editor. Select Run to view the results.




