Good afternoon!
I'm trying to run a query on a table to get the first record based on an account number.
On my table, i have multiple records for each account. What my goal is to get the first record for each individual account number (see attached image). I want the most current year for the account (i.e. i want the 01/01/09 record, not the 01/01/07 record). I've tried the following query, however it doesn't work the way I indent it to:
My ultimate goal is to pull the entire record's information that is brought in in the subquery, but I'm really unsure how to do that. I'm not even sure if this is possible, outside of writing VB code, which I'd like to stear away from if at all possible.
Any help would be GREATLY appreciated!
I'm trying to run a query on a table to get the first record based on an account number.
On my table, i have multiple records for each account. What my goal is to get the first record for each individual account number (see attached image). I want the most current year for the account (i.e. i want the 01/01/09 record, not the 01/01/07 record). I've tried the following query, however it doesn't work the way I indent it to:
Code:
SELECT
S.[ACCT_NUM], S.[PAID_FROM]
FROM
SARS_ACCT AS S
WHERE
S.[PAID_FROM] = (
SELECT TOP 1 S1.[PAID_FROM]
FROM SARS_ACCT AS S1
WHERE S1.[ACCT_NUM]=S.[ACCT_NUM]
ORDER BY
S1.[ACCT_NUM] ASC,
S1.[PAID_FROM] DESC)
Any help would be GREATLY appreciated!
Comment