My table structure (in SQL Server) looks something like this: (D1 is more recent than D2, PK is a normal Identity(1,1) column)
Name Type Score Date
A1 B1 C1 D1
A1 B2 C2 D1
A1 B1 C3 D2
What I need to do is find the latest Score values for each unique combination of Name and Type, i.e.:
A1 B1 C1 D1
A1 B2 C2 D1
I had originally done this by just using yesterday’s date, but not everything is updated daily so sometimes scores were missing.
I can get the unique combinations I need to look at with a simple
SELECT Name, Type FROM Table GROUP BY Name, Type ORDER BY MAX(Date)
but I obviously can’t add the other two columns or the groups are no longer unique.
I’ve had a look at similar questions but they all have differences that make them less useful for me.
Any help is much appreciated. I have a feeling that it’s a fairly simple problem and that I just don’t know enough to figure it out!
1 Answer