[LeetCode] 1965. Employees With Missing Information

2022. 6. 16. 00:52SQL

SELECT employee_id
FROM (SELECT e.employee_id
    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 employees AS e
    RIGHT JOIN salaries AS s
    ON e.employee_id = s.employee_id
    WHERE e.name IS NULL)sub
ORDER BY 1
  • OUTER JOIN : FULL OUTER JOIN , LEFT OUTER JOIN, RIGHT OUTER JOIN 
  • FULL OUTER JOIN 

=

LEFT JOIN 

UNION

RIGHT JOIN 

 

  • UNION 을 할때는 컬럼의 수가 같아야 함