Skip to content
Advertisement

Latest entry in a group SQL Server

Given the sample data below, I need a list of the ids whose latest entry is Rejected. Thus, I need to see id 2 because its latest is 6/4/2020 and that is Rejected. I do not want to see id 1 as its latest entry is Requested.

This is my pathetic attempt so far

But this will only bring back the latest date in each group. I need a list where the latest entry was Rejected. I expect the answer to be embarrassingly simple but I’m having a heck of a time with this.

Thanks

Carl

Advertisement

Answer

You can get this using row_number() function as shown below.

Here is the live db<>fiddle demo.

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