Skip to content
Advertisement

Return value at max date for a particular id

Here’s my sql server table

This seems like it should be easy to do, but I don’t know why I’m stuck. I’d like to select ONLY the max(date) and value at that max(date) for each id. I want to ignore all other dates that aren’t the max(date) with respect to each id.

Here’s what I’d like the table to look like:

I tried group by using max(date), but it didn’t group anything. I’m not sure what I’m doing wrong. Thanks in advance for the help!

Advertisement

Answer

You can use the following:

See Demo

User contributions licensed under: CC BY-SA
3 People found this is helpful
Advertisement