Of course all of this is moot because now that I know you have a table called TBL_ACCOUNTS with a field called ACCT_NBR and LOAN_NBR I've hacked into your system and am long gone with all funds this system houses.
Hardy har har.
Sorry for going MIA for several weeks; I got frustrated and this sort of fell by the wayside for a bit. I also apologize if I've come across as a bit of a dummy or a paranoid loon.
Let me start over and be explicit about what I'm trying to do and what I have to work with.
I have two tables, one that documents all of the daily transactions in our system and one that has account information. The two tables and their fields are listed below, with their data type and purpose in parentheses:
tblTrans
PROD_DT (Date; the transaction date)
ACCT_NBR (Decimal; the account number)
SEQ_NBR (Long; denotes what sequence this transaction was processed in the relation to all transactions run that day)
TRAN_CD (String; the transaction code)
TRAN_AMT (Decimal; the transaction amount)
tblAccounts
ACCT_NBR (Decimal; the account number)
ACCT_NAME (Text; the client's name)
In our system there are many types of transactions, and payment transactions can be either transaction code 211 or 710.
What I need to do is build a query that returns the following information for every account in tblAccounts:
ACCT_NBR
ACCT_NM
PROD_DT
TRAN_CD
TRAN_AMT
The trick is that I only want one return for each account; I want to limit the TRAN_CD returns to the two transaction codes I mentioned above (211 or 710), and I only want the most recent transaction.
To be clear: if the following transactions were posted to an account:
TRAN 1
PROD_DT: 12/1/15
SEQ_NBR: 47
TRAN_CD: 211
TRAN 2:
PROD_DT: 12/13/15
SEQ_NBR: 13
TRAN_CD: 211
TRAN 3:
PROD_DT: 12/13/15
SEQ_NBR: 17
TRAN_CD: 710
TRAN 4:
PROD_DT: 12/13/15
SEQ_NBR: 52
TRAN_CD: 138
...I would want the query to return TRAN 3, because (a) the TRAN_CD matches my criteria, (b) it has the highest value in the PROD_DT field, and (c) of the transactions on that date, it has the highest value in SEQ_NBR.
I'll obviously need at least one subquery, but this nothing I've tried has worked and it's driving me insane. Any help you can provide would be greatly appreciated.