[LeetCode/SQL] 1965. Employees With Missing Information

Sooyeon·2023년 12월 4일
0

문제풀이 

목록 보기
67/95
post-thumbnail

[LeetCode/SQL]


📌 1965. Employees With Missing Information

문제

풀이

직원 이름이 없거나,월급이 없는 정보를 출력하라.

방법 I

  • JOINUNION을 사용하여,각 테이블별 공통이 아닌 정보 출력
FROM Employees as e 
LEFT JOIN Salaries as s
ON e.employee_id=s.employee_id
WHERE s.salary IS NULL
UNION
SELECT s.employee_id
FROM Salaries as s 
LEFT JOIN Employees as e
ON e.employee_id=s.employee_id
WHERE e.name IS NULL

ORDER BY employee_id

방법 II

  • WHERENOT IN을 사용
SELECT employee_id
FROM Employees as e 
WHERE employee_id NOT IN (SELECT employee_id
                            FROM Salaries)
UNION
SELECT employee_id
FROM Salaries as s
WHERE employee_id NOT IN (SELECT employee_id
                          FROM Employees)
ORDER BY employee_id

0개의 댓글