Site: LeetCode
Difficulty per Site: Easy
Write a solution to report all the employees with their primary department. For employees who belong to one department, report their only department.
Return the result table in any order. [Full Description]
-- Submitted Solution
SELECT
employee_id
,department_id
FROM Employee
GROUP BY employee_id
HAVING COUNT(department_id) = 1
UNION
SELECT
employee_id
,department_id
FROM Employee
WHERE primary_flag = 'Y'
;
-- LeetCode Solution
-- Site solution essentially the same.
TODO
UNION