Mid Detailed answer Window Functions SQL & Databases

Explain ROW_NUMBER, RANK, and DENSE_RANK with a query.

Short answer: ROW_NUMBER gives unique sequence even for ties. RANK leaves gaps after ties. DENSE_RANK does not leave gaps. All use OVER (ORDER BY ...).

Sample solution

T-SQL
SELECT Name, Score,
       ROW_NUMBER() OVER (ORDER BY Score DESC) AS rn,
       RANK()       OVER (ORDER BY Score DESC) AS rnk,
       DENSE_RANK() OVER (ORDER BY Score DESC) AS dense_rnk
FROM Students;
Memorize one example with ties: scores 100,100,90 → RANK 1,1,3 vs DENSE_RANK 1,1,2.
Toolliyo Assistant
Ask about tutorials, ebooks, training, pricing, mentor services, and support. I use public site content only—not admin or internal tools.

care@toolliyo.com

Need callback? Share your details