I only have SQL Server 2008R2, therefore I do not have all the window functions available since SQL Server 2012.
I have a table that looks like this:
I would like to retrieve a result set like this, where each category has the ID associated with the lowest order number, and also the ID associated with the highest order number:
I am looking for the TSQL select statement that would do this.
Best Answer
You could do this without the new (2012+) window function
FIRST_VALUE()
, using theROW_NUMBER()
. But you could also do it usingOUTER APPLY
: