I have below data in my ColorAssign
table;
| PKID | Name | Type | HasAssigned |
| 11 | Red | 1 | True |
| 12 | Blue | 2 | False |
| 13 | Yellow | 3 | False |
| 14 | Red1 | 1 | False |
| 15 | Yellow1 | 3 | True |
| 16 | Blue1 | 2 | False |
Note in this above table I have color types in type field and assign status in HasAssigned
field also with different primary keys with different names (can be same name - but type is the identifier to find the actual color).
My goal is to get the data as the condition:-
Find the records with the color type with Hasassigned = true
or if no records for the type has true. Then type with Hasassigned = false
of color type. So my resultset would be;
| 11 | Red | 1 | True |
| 12 | Blue | 2 | False |
| 15 | Yellow1 | 3 | True |
| 16 | Blue1 | 2 | False |
What are all the ways we can do this, with a focus on optimization?