How to select nth Highest Record
ROW_NUMBER() OVER (ORDER BY marks DESC) gives 1,2,3 with no ties sharing a number. RANK() gives 1,1,3 if two toppers. DENSE_RANK() gives 1,1,2.
Nth highest — wrap in a subquery WHERE rn = 3. That’s the ‘3rd highest salary’ pattern.
Trap — ROW_NUMBER without ORDER BY in OVER — meaningless ranks.
On the example next to this theory: How to select nth Highest Record — sELECT projects columns; WHERE filters; ORDER BY sorts.
FROM students
│
▼
WHERE city = 'Pune'
│
▼
SELECT name, marksExam tip
ROW_NUMBER() OVER (ORDER BY salary DESC) then WHERE rn = 3.