Loading the editor…
Pair every employee with the department they sit in.
Finance is mapping headcount to office location for the budget workbook. Every current employee has a department.
Return employee_name, title, department_name, and location. Sort by department name, then employee name.
| id | name | location |
|---|---|---|
| 1 | Engineering | Berlin |
| 2 | Sales | London |
| 3 | People | New York |
| id | name | department_id | manager_id | hire_date | title | |
|---|---|---|---|---|---|---|
| 1 | Amira Hassan | amira@querylab.example | 1 | NULL | 2021-03-01 | Staff Engineer |
| 2 | Leo Martins | leo@querylab.example | 1 | 1 | 2022-06-15 | Software Engineer |
| 3 | Priya Nair | priya@querylab.example | 1 | 1 | 2023-01-09 | Software Engineer |
| id | employee_id | amount | effective_date |
|---|---|---|---|
| 1 | 1 | 145000 | 2024-01-01 |
| 2 | 1 | 132000 | 2023-01-01 |
| 3 | 2 | 98000 | 2024-01-01 |
| id | employee_id | title | department_id | start_date | end_date |
|---|---|---|---|---|---|
| 1 | 2 | Junior Engineer | 1 | 2022-06-15 | 2023-12-31 |
| 2 | 3 | Junior Engineer | 1 | 2023-01-09 | 2024-03-31 |
| 3 | 5 | SDR | 2 | 2023-04-17 | 2024-06-30 |
Ctrl or Cmd + Enter runs the query. The database resets on every run.
Run the query to see rows from the sample database.
Next exercise: Above-average current salaries
Related: Employees and their managers, Hires since 2023