[LeetCode] SQL 50 / Oracle / 1378. Replace Employee ID With The Unique Identifier

2024. 1. 6. 16:19Coding/LeetCode-SQL

문제링크

https://leetcode.com/problems/replace-employee-id-with-the-unique-identifier/description/?envType=study-plan-v2&envId=top-sql-50

 

Replace Employee ID With The Unique Identifier - LeetCode

Can you solve this real interview question? Replace Employee ID With The Unique Identifier - Table: Employees +---------------+---------+ | Column Name | Type | +---------------+---------+ | id | int | | name | varchar | +---------------+---------+ id is t

leetcode.com

 

문제

 

코드

/* Write your PL/SQL query statement below */
SELECT B.unique_id, A.name
FROM Employees A, EmployeeUNI B
WHERE A.id=B.id(+);

 

1. Employee 테이블과 EmployeeUNI 테이블의 기본키가 id이므로 두 테이블의 id를 join해준다. 

이때,  'If a user does not have a unique ID replace just show null'이라고 했으므로

(유저가 unique ID 값을 가지고 있지 않으면 null 값으로 대신 표현하라)

조인 테이블의 기준은 A가 되고, B는 참조 테이블이 된다. 따라서 (+)를 B.id 뒤에 붙여준다.