Home › Interview Questions › Given the list of salaries [500, 300, 300, 400, 40…

Given the list of salaries [500, 300, 300, 400, 400, 200], what would the ROW_NUMBER() values be if you order by salary descending?

🟢 Easy Conceptual Junior level
1Times asked
Sep 2026Last seen
Sep 2026First seen

💡 Model Answer

ROW_NUMBER() assigns a unique sequential number to each row in the result set, so even if two rows have the same salary, they will receive different row numbers. In the example, after sorting by salary descending, the order is 500, 400, 400, 300, 300, 200. Applying ROW_NUMBER() yields 1 for 500, 2 for the first 400, 3 for the second 400, 4 for the first 300, 5 for the second 300, and 6 for 200. If you need a logical rank that treats equal salaries as the same rank, use DENSE_RANK() instead. DENSE_RANK() would assign 1 to 500, 2 to both 400s, 3 to both 300s, and 4 to 200. This is useful when you want to identify the nth distinct salary level. The choice between ROW_NUMBER() and DENSE_RANK() depends on whether you need unique identifiers for every row or a ranking that collapses ties. In many reporting scenarios, DENSE_RANK() is preferred for clarity, while ROW_NUMBER() is used for pagination or when you need to enforce a strict ordering.

This answer was generated by AI for study purposes. Use it as a starting point — personalize it with your own experience.

🎤 Get questions like this answered in real-time

Assisting AI listens to your interview, captures questions live, and gives you instant AI-powered answers on a discreet on-screen overlay.

Get Assisting AI — Starts at ₹500