The Employee table has a self-referencing ReportsTo column. Use a self-join to show each employee alongside their manager's name.
Write a query that joins the Employee table to itself to show employee-manager relationships.
| Column | Type |
|---|---|
| EmployeeId | INTEGER (Primary Key) |
| LastName | TEXT |
| FirstName | TEXT |
| Title | TEXT |
| ReportsTo | INTEGER (Self-referencing Foreign Key) |
| BirthDate | TIMESTAMP |
| HireDate | TIMESTAMP |
| Address | TEXT |
| City | TEXT |
| State | TEXT |
| Country | TEXT |
| PostalCode | TEXT |
| Phone | TEXT |
| Fax | TEXT |
| TEXT |
SELECT a.column, b.column
FROM table a
LEFT JOIN table b ON a.foreign_key = b.primary_key;
Ready to take your skills to the next level? Enroll in our comprehensive Data Analyst Career Track to master SQL, Python, Excel, and Power BI.
Run your code to see the result here.