Skip to content
Advertisement

Get last and first record using rank()

I need to get first and last record (ordered by Date column) from table for certain SSID. It is not a problem if there is more records with same max or min date. All I need is union all.

I am getting last record having max(date) with:

How to I get first record (min(Date)) as well (same thing only with order by Date asc) with single select and without using ranking again?

I’m using MSSQL 2017.

Advertisement

Answer

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