For each employee, return unique_identifier and emp_name, matching on emp_code. If an employee has no unique identifier, show NULL.
Input Table(s)
Table employee_info, primary key emp_code. Each row holds the code and name of one employee in the organization.
| Column | Type | Meaning |
|---|
| emp_code | INT | Employee code, unique per employee |
| emp_name | VARCHAR | Employee name |
Table unique_identifiers, primary key (emp_code, unique_identifier). Each row holds an employee code and a unique identifier assigned to that employee.
| Column | Type | Meaning |
|---|
| emp_code | INT | Employee code |
| unique_identifier | INT | Identifier assigned to that employee |
Output Contract
Return exactly these columns, in this order:
| Column | Type | Meaning |
|---|
| unique_identifier | INT | The employee's identifier, or NULL when the employee has none |
| emp_name | VARCHAR | The employee's name |
Sort the rows by emp_code ascending (the column is not returned), then by unique_identifier ascending. No rounding applies.
Example
employee_info:
| emp_code | emp_name |
|---|
| 101 | Priya |
| 102 | Marcus |
| 103 | Elena |
| 104 | Tomas |
unique_identifiers:
| emp_code | unique_identifier |
|---|
| 101 | 5001 |
| 103 | 5003 |
| 103 | 5017 |
| 105 | 5005 |
Expected result:
| unique_identifier | emp_name |
|---|
| 5001 | Priya |
| NULL | Marcus |
| 5003 | Elena |
| 5017 | Elena |
| NULL | Tomas |
Marcus and Tomas have no identifier, so each appears once with NULL. Elena has two identifiers and appears once for each. The row for code 105 matches no employee and is not returned.
Constraints and Clarifications
-
Every employee in
employee_info
appears in the result at least once.
-
An employee with several identifiers appears once per identifier. An employee with none appears exactly once, with
NULL
in
unique_identifier
.
-
Rows in
unique_identifiers
whose
emp_code
matches no employee are ignored.
-
unique_identifier
is never
NULL
in the source table, so a
NULL
in the result always means the employee has no identifier.
-
Two employees can share a name. They are still separate employees and each gets their own rows.