[LeetCode/SQL]
풀이
직원 이름이 없거나,월급이 없는 정보를 출력하라.
방법 I
JOIN
과 UNION
을 사용하여,각 테이블별 공통이 아닌 정보 출력
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
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