Link to home
Create AccountLog in
Avatar of deedub84
deedub84Flag for United States of America

asked on

Subquery to get max(date) from transaction file by customer

Hi Experts,

I have a transaction journal file with customer sales and related information.

One field is a sales code, which can change overtime, and isn't always entered (it should be mandatory input but currently isn't).  I need to come up with a query that gives me a Name and the sales code from the latest dated transaction in the case where there is one, or "none" if there isn't one at all in any of the transactions for that company.

I have attempted a subquery with max(date) but it is taking forever to run....

This is what I have currently:

SELECT QTL.Name, QTL.Salescode
FROM QuickenTrxList AS QTL
WHERE (((QTL.Date)=(SELECT Max(Date) From QuickenTrxList as S WHERE S.Name = QTL.Name )));

Deedub
Avatar of Mike Eghtebas
Mike Eghtebas
Flag of United States of America image

SELECT Name, Nz(Salescode,"none") As Saves_Code, Max(Date) FROM QuickenTrxList Group By Name, Nz(Salescode,"none") Order By Name

Mike
SOLUTION
Avatar of Mike Eghtebas
Mike Eghtebas
Flag of United States of America image

Link to home
membership
Create a free account to see this answer
Signing up is free and takes 30 seconds. No credit card required.
See answer
ASKER CERTIFIED SOLUTION
Link to home
membership
Create a free account to see this answer
Signing up is free and takes 30 seconds. No credit card required.