How would you find the third highest salary in the employees table, not department-wise?
💡 Model Answer
To find the third highest salary in the employees table without grouping by department, you can use a ranking function or a subquery. A common approach is to use the ROW_NUMBER() window function partitioned over the entire table, ordering salaries in descending order, and then filter for row number 3. Example in SQL Server: SELECT salary FROM (SELECT salary, ROW_NUMBER() OVER (ORDER BY salary DESC) AS rn FROM employees) AS t WHERE rn = 3; This returns the third highest distinct salary. If you need to ignore duplicates, use DENSE_RANK() instead of ROW_NUMBER(). Alternatively, you can use a subquery that selects the distinct salaries, orders them, and limits the result: SELECT DISTINCT salary FROM employees ORDER BY salary DESC LIMIT 2,1; In MySQL, you can use LIMIT 2,1 to skip the top two salaries. Both methods give the third highest salary across all departments, satisfying the requirement.
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