Department Top Three Salaries
A hard-tier problem at 58% community acceptance, tagged with Database. Reported in interviews at Dell and 4 others.
Department Top Three Salaries is a hard SQL problem that tests your ability to work with window functions and ranking logic. Google, Dell, Accenture, TCS, and Ozon have all asked this. The trick isn't complexity for its own sake. It's isolating the top earners per department without self-joins or expensive subqueries. Most candidates either over-engineer it with multiple passes or miss the subtle requirement that you need exactly three salaries per department, not just three rows. With a 57% acceptance rate, this problem rewards precise SQL thinking over brute force.
Companies that ask "Department Top Three Salaries"
Department Top Three Salaries is the kind of problem that decides whether you pass. StealthCoder reads the problem on screen and surfaces a working solution in under 2 seconds. Invisible to screen share. The proctor sees nothing. Made by a working FAANG engineer who treats the OA the way companies treat hiring: as a game with rules you should know.
Get StealthCoderThe problem asks you to surface the top three salaries in each department. The gotcha: you can't just rank all salaries globally and filter. You need window functions scoped to the department partition. DENSE_RANK or ROW_NUMBER with PARTITION BY department_id is the core move. The friction point is handling edge cases. Some departments have fewer than three employees. Your query must still return all employees with rank 1, 2, or 3 within their department without bloating the result. Many candidates write correct logic but include rows beyond the top three because they don't properly filter the ranking window. If you hit this problem live and blank on window function syntax or the partition scope, StealthCoder solves it in seconds, invisible to the proctor.
Pattern tags
You know the problem.
Make sure you actually pass it.
Department Top Three Salaries recycles across companies for a reason. It's hard-tier, and most candidates blank under the timer. StealthCoder is the hedge: an AI overlay invisible during screen share. It reads the problem and surfaces a working solution in under 2 seconds. Made by a working FAANG engineer who treats the OA the way companies treat hiring: as a game with rules you should know. Works on HackerRank, CodeSignal, CoderPad, and Karat.
Department Top Three Salaries interview FAQ
Do I need a self-join for this problem?+
No. Self-joins are the slow path. Window functions like DENSE_RANK or ROW_NUMBER with PARTITION BY department_id do the work in one pass. A single window-ordered-by-salary gives you rank per department without redundant table scans.
What's the difference between ROW_NUMBER and DENSE_RANK here?+
ROW_NUMBER assigns a unique rank even if salaries are equal. DENSE_RANK skips no ranks when salaries match. For 'top three salaries,' DENSE_RANK is safer because it returns all employees tied at the third salary level, not just three rows.
How do I handle departments with fewer than three employees?+
Your WHERE clause should filter WHERE rank <= 3, not WHERE rank = 3. This naturally includes all departments with 1, 2, or 3 employees while still limiting larger departments to their top three earners.
Is this still asked at companies like Google and Dell?+
Yes. Google, Dell, Accenture, TCS, and Ozon have all reported this problem. It's a classic assessment for SQL depth. Acceptance rate sits at 57%, so it's not trivial, but it's foundational for database roles.
What's the most common mistake?+
Not filtering the ranking result correctly. Candidates rank salaries but forget to add WHERE rank_column <= 3, or they use ROW_NUMBER and miss tied salaries. Write the window function first, test it without filtering, then add the WHERE clause.
Want the actual problem statement? View "Department Top Three Salaries" on LeetCode →