LeetCode - 1965. Employees With Missing Information (MySQL)

조민수·2024년 7월 1일
0

LeetCode

목록 보기
46/61

Easy, SQL - FULL JOIN

RunTime : 489 ms


문제

Write a solution to report the IDs of all the employees with missing information. The information of an employee is missing if:

  • The employee's name is missing, or
  • The employee's salary is missing.

Return the result table ordered by employee_id in ascending order.
The result format is in the following example.


풀이

  • 두 테이블에 대해 각각의 조건에 맞는 id 들을 찾아 UNION 하는 문제
  • 첫 번째 쿼리에서 Employees에 있지만 Salaries에 없는 id를 찾고
    두 번째 쿼리에선 반대로 동작하게끔 RIGHT JOIN을 사용한다.
SELECT e.employee_id FROM Employees as e
LEFT JOIN Salaries as s USING(employee_id)
WHERE salary IS NULL

UNION

SELECT s.employee_id FROM Employees as e
RIGHT JOIN Salaries as s USING(employee_id)
WHERE name IS NULL

ORDER BY employee_id;
profile
사람을 좋아하는 Front-End 개발자

0개의 댓글