Employees Earning More Than Their Manager
Reported by candidates from Mygate's online assessment. Pattern, common pitfall, and the honest play if you blank under the timer.
The Mygate OA reported in September 2026 asks a SQL question that looks like a freebie and then punishes sloppy NULL and tie handling. You get an employees table with salary and manager_id, and you return everyone who strictly out-earns their direct manager. It's a self-join, nothing fancier. The trap is in the fine print: top-level employees with no manager, equal salaries, and duplicate names. If you blank on the join shape during the live assessment, StealthCoder is the safety net that reads the schema and hands you the query.
The problem
The employees table contains one row per employee, including their salary and the ID of their direct manager. Return the employee_id and employee_name of every employee whose salary is strictly greater than their direct manager's salary. Sort the result by employee_id in ascending order. A null manager ID means the employee has no manager and must be excluded. Every non-null manager ID refers to an employee in the table. Employees with equal salaries do not qualify. Compare only with the direct manager, even when a management chain contains more people. Different employees may have the same name. Tables employees: employee_id PK (Integer), employee_name (Text), salary (Integer), manager_id (Integer) Constraints The table contains between 0 and 10^4 rows. employee_id is unique and between 1 and 10^9. employee_name is nonempty text of at most 100 characters. salary is an integer between 0 and 10^9. An employee cannot be their own manager. Management chains are acyclic.
Reported by candidates. Source: FastPrep
Pattern and pitfall
The trick is a self-join. Alias employees twice, e for the employee and m for the manager, and join on e.manager_id = m.employee_id. An inner join does the heavy lifting here. Employees with a NULL manager_id never match any row, so they drop out without a special filter. Then add WHERE e.salary > m.salary. Use strictly greater, not >=, because equal pay is explicitly excluded. Select e.employee_id and e.employee_name, then ORDER BY e.employee_id ASC. The common pitfalls: using a LEFT JOIN and then comparing against NULL, which silently fails, joining on name instead of ID (names repeat), or walking up the whole management chain when only the direct manager counts. An empty table just returns zero rows, so no extra handling is needed. If the query shape slips your mind mid-OA, StealthCoder is the hedge that gives you the working join.
Drill it cold or hedge it with StealthCoder. Either way, don't walk into the OA hoping you remember the trick.
You can drill Employees Earning More Than Their Manager cold, or you can hedge it. StealthCoder runs invisibly during screen share and surfaces a working solution in under 2 seconds. The proctor sees the IDE. They don't see what's behind it. Made for the candidate who got the OA invite this morning and has 72 hours, not six months.
Get StealthCoderRelated leaked OAs
This OA pattern shows up on LeetCode as employees earning more than their managers. If you have time before the OA, drill that.
You've seen the question.
Make sure you actually pass Mygate's OA.
Mygate reuses patterns across OAs. Made for the candidate who got the OA invite this morning and has 72 hours, not six months. Works on HackerRank, CodeSignal, CoderPad, and Karat.
Employees Earning More Than Their Manager FAQ
How hard is the Mygate employees-earning-more-than-manager question really?+
Easy if you know self-joins, which is the whole point. The logic is one join and one comparison. The difficulty is in the edge rules: NULL managers, equal salaries, and sorting. Write the join carefully and you're done in a couple of minutes.
What's the trick to solving it?+
Join the employees table to itself. Alias one copy as the employee and the other as the manager, matching e.manager_id to m.employee_id. Then filter where e.salary > m.salary. That's the full solution, plus an ORDER BY employee_id.
Do I need to handle NULL manager_id explicitly?+
Not with an inner join. A NULL manager_id never equals any employee_id, so those rows get excluded automatically. If you use a LEFT JOIN instead, the salary comparison against NULL evaluates to unknown and filters them out anyway, but the inner join is cleaner.
Should I use >= or > for the salary comparison?+
Use strictly greater than. The problem says employees with equal salaries do not qualify. Using >= is the most common wrong answer on this one, and it'd fail any hidden test with a tie between employee and manager.
How do I prepare for this in 48 hours?+
Write a self-join from scratch three or four times until it's automatic. Then practice NULL behavior in joins and comparisons, plus ORDER BY. Also review a subquery version using a correlated lookup, so you have a backup approach if the join doesn't come to mind.