Skip to main content
Back to problems
Leetcode
Easy
Hash Maps
Arrays
Strings
Replace Employee Id With The Unique Identifier

Replace each employee id with its unique identifier when a matching record exists.

Acceptance 100%
Problem Statement

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

  • Employees table: columns id, name
  • EmployeeUNI table: columns id, unique_id
  • Join condition: Employees.id = EmployeeUNI.id

Output Format

A table with columns:

  1. unique_id
  2. name

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
Examples
Sample cases returned by the problem API.

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.

Guided hints
Editorial and discussion links
Concept map and variants
Sign in to unlock
Track your progress
Sign in to bookmark this problem, save notes, and manage its revision plan.