Employees can belong to multiple departments. When an employee joins a new department, they can decide which one is their primary department. However, if an employee belongs to only one department, that department is their primary department by default.
Write an SQL query to report all the employees with their primary department.
Rules:
- If an employee has a record with primary_flag = 'Y', choose that department.
- If an employee only belongs to one department, choose that department (regardless of flag).
- Output columns: employee_id, department_id.
- Results must be sorted by employee_id in ascending order.