I’m trying to select most recent date from one table (invoice) to a customer on another table. I’m not looking for a single customer, but several. What I want to do looks something like this:
select C.[Last Name], C.[First Name], C.[State], I.[Date]
From myDb.dbo.Customer C
left join myDb.dbo.Invoice I on I.CustomerID = C.CustomerID
where c.state=@State and i.date = max(i.date)
I know I can’t have the Max() in the where, and I tried using HAVING. I can’t assign a local var for the customerID and do a where i.date = (select...). I’m trying to keep this all as one statement as this is being executed on several DB’s from a single DB.
update:
I’ve decided to change my design requirements as this wasn’t the most optimal solution.
You possibly want to group:
Updated: