Snoopy [리트코드/SQL] 11. Employees With Missing Information (1965)
코딩테스트/리트코드 SQL

[리트코드/SQL] 11. Employees With Missing Information (1965)

Sooyoon Jeong 2022. 12. 16.

목차


🤔 문제 분석

1) 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.

2) Return the result table ordered by employee_id in ascending order.

 

💡 풀이

(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)

ORDER BY employee_id

댓글