Replace Employee ID with Unique Identifier
Preview mode. Log in to edit, run, submit, and save progress.
Description
You have two tables: Employees and EmployeeUNI. Each employee has an id and a name. Some employees have been assigned a unique_id in the EmployeeUNI table, but not all. Write a SQL query to show the unique_id and name of each employee. If an employee does not have a unique_id, show NULL instead. Return the result in any order. (id, unique_id) is the primary key of EmployeeUNI.
Database Schema
Employees
| Column Name | Type | Description |
|---|---|---|
| id | INT | Primary key |
| name | VARCHAR | Employee name |
EmployeeUNI
| Column Name | Type | Description |
|---|---|---|
| id | INT | FK to Employees |
| unique_id | INT | Unique identifier assigned |
Example
Employees
| id | name |
|---|---|
| 1 | Alice |
| 7 | Bob |
| 11 | Meir |
| 90 | Winston |
| 3 | Jonathan |
EmployeeUNI
| id | unique_id |
|---|---|
| 3 | 1 |
| 11 | 2 |
| 90 | 3 |
Output
| unique_id | name |
|---|---|
| NULL | Alice |
| NULL | Bob |
| 2 | Meir |
| 3 | Winston |
| 1 | Jonathan |
Explanation:
Alice and Bob have no unique_id - show NULL. Meir → 2, Winston → 3, Jonathan → 1.
Approach hint
Start with a simple approach, explain the trade-off, then move toward a cleaner or more scalable solution.
Common mistake
Skipping assumptions, edge cases, or trade-offs can make an otherwise good answer feel incomplete.
Employees
| id | name |
|---|---|
| 1 | Alice |
| 7 | Bob |
| 11 | Meir |
| 90 | Winston |
| 3 | Jonathan |
EmployeeUNI
| id | unique_id |
|---|---|
| 3 | 1 |
| 11 | 2 |
| 90 | 3 |
Output
| unique_id | name |
|---|---|
| NULL | Alice |
| NULL | Bob |
| 2 | Meir |
| 3 | Winston |
| 1 | Jonathan |