Home › Interview Questions › So what about Dave? His salary was 90,000 rupees. …

So what about Dave? His salary was 90,000 rupees. How would that affect the result of the highest-paid-per-department query?

🟡 Medium Conceptual Mid level
1Times asked
Oct 2026Last seen
Oct 2026First seen

💡 Model Answer

If Dave's salary is 90,000 rupees and he is the highest paid employee in his department, the query that uses ROW_NUMBER() OVER (PARTITION BY dept ORDER BY salary DESC) and filters for rn = 1 will return Dave as the top employee for that department. If someone else in the same department has a higher salary, Dave would not appear in the result set. The query works by assigning a rank to each employee within their department based on salary, then selecting only the rows with rank 1. This approach is efficient because it can use indexes on the department and salary columns. If you need to handle ties (e.g., multiple employees with the same highest salary), you could replace ROW_NUMBER() with RANK() or DENSE_RANK() to include all tied employees. Alternatively, a correlated subquery that compares each employee's salary to the maximum salary in their department can achieve the same result, but the window function approach is generally faster on large datasets. In summary, Dave will appear in the output only if his salary is the maximum in his department; otherwise, he will be excluded.

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