Replace each employee id with its unique identifier when a matching record exists.
Problem
You are given two tables:
Employees(id, name)EmployeeUNI(id, unique_id)
Each row in Employees represents an employee, and EmployeeUNI stores the unique identifier for some employee ids.
Return the result of listing every employee's unique_id next to their name. If an employee does not have a matching row in EmployeeUNI, the unique_id should be null.
This is equivalent to performing a left join from Employees to EmployeeUNI on id.
Input Format
Employeestable: columnsid,nameEmployeeUNItable: columnsid,unique_id- Join condition:
Employees.id = EmployeeUNI.id
Output Format
A table with columns:
unique_idname
The rows should include every employee from Employees, using null for missing unique ids.
Constraints
- Preserve all rows from
Employees - Each employee may or may not have a matching unique id
- Output order is not important unless otherwise specified
Example 1
Input
Employees +----+-------+ | id | name | +----+-------+ | 1 | Alice | | 2 | Bob | | 3 | Carol | +----+-------+ EmployeeUNI +----+-----------+ | id | unique_id | +----+-----------+ | 1 | 101 | | 3 | 103 | +----+-----------+
Output
+-----------+-------+ | unique_id | name | +-----------+-------+ | 101 | Alice | | null | Bob | | 103 | Carol | +-----------+-------+
Explanation
Alice and Carol have matching rows in EmployeeUNI, while Bob does not, so Bob's unique_id is null.
Premium problem context
Unlock deeper context for this problem
Premium adds guided hints, editorial links, similar variants, discussion resources, and concept maps so you can understand why a problem matters, not just solve it once.