Cellwise · SQL track

Joining a table to itself

Find managers, and count their teams.

The employees table records each person’s manager by id. To see the manager’s name, join the table to itself, giving each copy a short alias such as e for employee and m for manager.

An INNER JOIN drops people with no manager. A LEFT JOIN keeps them, with NULL where the manager would be.

What you’ll do

Start the lesson, free