About this problem
This problem practises the classic downward recursive CTE: finding everyone in a manager’s reporting tree. From employees, where manager_id points to each person’s manager, you return all direct and indirect reports of e2 (Bob) at any depth. The anchor is Bob’s direct reports; the recursive step finds anyone whose manager_id matches someone already found, and repeats until no new rows appear. It is the same shape as org-chart access rules, cost roll-ups and bill-of-materials questions, where the depth is not known in advance.
The mistake that looks right is a single join: selecting rows whose manager_id is e2 returns Bob’s direct reports and stops. The sample has a third level under Bob, so one join already misses someone, and real org charts go deeper still. The short answer is convincing because every row it returns really is in Bob’s team. The opposite slips are about where you start. Anchoring on the root (the row with NULL manager_id) expands the whole company, including Carol’s branch, which has nothing to do with Bob. Starting from e2 itself puts Bob in the output, and the prompt says to exclude him. Check the join direction as well: matching the current row’s manager_id to the found set walks up towards Alice instead of down to Bob’s team. The result is a set of people, so check that nobody appears twice.
Read the lesson: Recursive CTEs & Hierarchies (P21) →