Skip to content
Advertisement

TSQL – Select Latest Date by 2 Type

I need select data in SQL Server. I have a Data example like this

I want to get 4 records (in table will have a lot of SubId) 2 records latest date by SubId = 1 2 records latest date by SubId = 2 Following example, I expect Select with like table Output

Example “tooltip”

I try with Union but It’s only Order after Union. It’s not the result I want.

Please, Help me to select this. Thank you.

Advertisement

Answer

You can use the Row_Number() function as shown below:

Live db<>fiddle demo

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