Primary Department for Each Employee
Task: Report all the employees with their primary department. For employees who belong to one department, report their only department.
Table: Employee
+---------------+------------+
| Column Name | Type |
+---------------+------------+
| employee_id | INT |
| department_id | INT |
| primary_flag | varchar(1) |
+---------------+------------+
Input: Employee table:
+-------------+---------------+--------------+
| employee_id | department_id | primary_flag |
+-------------+---------------+--------------+
| 1 | 1 | N |
| 2 | 1 | Y |
| 2 | 2 | N |
| 3 | 3 | N |
| 4 | 2 | N |
| 4 | 3 | Y |
| 4 | 4 | N |
+-------------+---------------+--------------+
Output:
+-------------+---------------+
| employee_id | department_id |
+-------------+---------------+
| 1 | 1 |
| 2 | 1 |
| 3 | 3 |
| 4 | 3 |
+-------------+---------------+