Skip to the content

Paige is leaving

Problem

Paige, employee 3, is leaving the company. Before her row gets deleted, her people need somewhere to go: whoever reports to her today will report to whoever Paige reports to. Nobody is left without a boss, and nobody is left pointing to someone who's gone.

Her people are the ones who have her as their boss, whatever department they're in. And don't type in Paige's boss by hand: the change has to work just as well on the day she reports to someone else.

Write the handoff and the delete. It's graded by looking at who the boss is for each person still at the company.

What it has to return

After your code, this query runs

SELECT id, name, boss_id FROM employees;

These rows, in any order

idnameboss_id
1CarolNULL
2Mark1
4Rachel2
5Nicole2
6Samuel1
7Lydia1
8Frank1
9Grace1

This is what comes out with the data in the practice database this challenge uses. The column names don’t count, so name yours however you like: what counts is how many there are and the order they come in. Besides this one, the challenge has hidden tests with other data that are revealed when you submit your solution.

You start with this

SQL

DELETE FROM employees
WHERE id = 3;
Solve this challenge

It opens in your browser, with the editor and the tests. This challenge is part of the full plan; the O(1) and O(log n) ones are free.

More O(n²) challenges

See all challenges →