본문 바로가기

SQL

(SQL) - LeetCode (easy) 1378. Replace Employee ID With The Unique Identifier

반응형

https://leetcode.com/problems/replace-employee-id-with-the-unique-identifier/

 

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

left outer join을 사용해본 문제였습니다.

📕 풀이방법

📔 풀이과정

Employees에서 EmployeeUNI를 id에 대해서 left outer join을 하게 되면 Employee의 name에 해당하는 id가 EmployeeUNI에 없다면 id를 null로 채워 select하게 됩니다.


📕 Code

📔 SQL

select u.unique_id, e.name from Employees e
left outer join EmployeeUNI u on e.id = u.id

*더 나은 내용을 위한 지적, 조언은 언제나 환영합니다.