This is a Microsoft SQL tutorial on the ROW_NUMBER function. This function allows you to create a column that counts the rows in your SQL results. You can access this column to solve multiple problems. This tutorial also shows how the ORDER BY works with ROW_NUMBER and how and why to use PARTITION BY.
Complimentary video:
Nested Selects: • MS SQL tutorial on nested selects