EDIT: I’m using SQL Server
I looked around for an example of this but couldn’t find anything so I’ll start a new thread…
I have 3 tables.
Account
- AccountID
- FirstName
- LastName
AccountEnroll
- AccountEnrollID
- AccountID
- AccountTypeID
- EnrollDate
AccountType
- AccountTypeID
- AccountType
The AccountEnroll table is a bridge table to track each customer’s enrollment history. I want to use the “EnrollDate” column to determine the current account type for each customer. I need to write a SELECT statement that can display AccountID, FirstName, LastName, (current)AccountType.
I am having trouble getting my resultset to display only the MAX(EnrollDate) record for each customer.
You can use common table expressions to do this pretty simply.