Suppose you have two tables, Employee and Department. Verbally explain how you would find the highest paid employee in each department.
1Times asked
Jun 2026Last seen
Jun 2026First seen
💡 Model Answer
I would use a window function to rank employees by salary within each department. The query would look like:
SELECT employee_id, name, department_id, salary
FROM (
SELECT e.*, ROW_NUMBER() OVER (PARTITION BY department_id ORDER BY salary DESC) AS rn
FROM Employee e
) t
WHERE rn = 1;
This returns the top-paid employee per department. If multiple employees share the same highest salary, you could use RANK() instead of ROW_NUMBER() to include all ties.
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 — invisible to screen sharing.
Get Assisting AI — Starts at ₹500