I need help to write a SQL
query to group all records for a particular person by the PersonId, LocationId and Role then choose the first IsActive = true record if it exists, otherwise, return the first IsActive = false. The table primary key is the PersonLocationId. There is a bunch of other columns that I also need to return for the result that is not there. Any suggestions?
| PersonLocationId | PersonId | LocationId | Role | IsActive |
| ---------------- | -------- | ---------- | ----------- | -------- |
| 1 | 1 | 222 | StorePerson | True |
| 2 | 1 | 222 | StorePerson | False |
| 3 | 1 | 222 | StorePerson | False |