I have the following employee_sequence table
| id | employee_id | sequence_id | is_completed |
|----|:-----------:|:-----------:|:------------:|
| 1 | 12 | 3 | 1 |
| 2 | 12 | 4 | 1 |
| 3 | 10 | 3 | 1 |
| 4 | 10 | 4 | 0 |
I am looking for how to get, in 1 query, the first row having is_completed = 0 for an employee. If no such row for that employee, then take first row having is_completed = 1
Example for employee_id = 12 (there is no is_completed = 0, so first row having is_completed = 1)
| id | employee_id | sequence_id | is_completed |
|----|:-----------:|:-----------:|:------------:|
| 1 | 12 | 3 | 1 |
Example for employee_id = 10 (first row having is_completed = 0)
| id | employee_id | sequence_id | is_completed |
|----|:-----------:|:-----------:|:------------:|
| 4 | 10 | 4 | 0 |