primary_flag
set to 'Y'.employee_id
and select those who appear exactly once (implying they belong to only one department).UNION
to combine the results from steps 1 and 2, ensuring no duplicates and that each employee's primary department is represented.employee_id
and department_id
for the primary department of each employee.erDiagram Employee { int employee_id int department_id varchar primary_flag primary_key (employee_id, department_id) }