[MySQL] FULL OUTER JOIN

테이블과 결과

Input: 
Employees table:
+-------------+----------+
| employee_id | name     |
+-------------+----------+
| 2           | Crew     |
| 4           | Haven    |
| 5           | Kristian |
+-------------+----------+
Salaries table:
+-------------+--------+
| employee_id | salary |
+-------------+--------+
| 5           | 76071  |
| 1           | 22517  |
| 4           | 63539  |
+-------------+--------+
Output: 
+-------------+
| employee_id |
+-------------+
| 1           |
| 2           |
+-------------+
Explanation: 
Employees 1, 2, 4, and 5 are working at this company.
The name of employee 1 is missing.
The salary of employee 2 is missing.

문제

Write an SQL query 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.

SELECT e.employee_id 
FROM Employees e 
LEFT JOIN Salaries s ON e.employee_id = s.employee_id
WHERE s.salary IS NULL 
  UNION 
SELECT s.employee_id  
FROM Employees e 
RIGHT JOIN Salaries s ON e.employee_id = s.employee_id
WHERE e.name IS NULL
  ORDER BY employee_id 
;

links

social