How can I find all rows in a table where val_b has a specific value, but if no such row exists, I would like to see if there are rows that match with less specificity, thus where val_b is null.
From the table below, I would like to select where val_a = X and val_b = T and get the row with ID:1 back.
If I select where val_a = X and val_b = V and get row with ID:3 and ID:4 back. Since row 1 and 2 didn't match, I will settle with the rows that have less specificity but still matches val_a.
| ID | val_a | val_b |
| -- | ----- | ----- |
| 1 | X | T |
| 2 | X | U |
| 3 | X | null |
| 4 | X | null |
| 5 | Y | null |
Is this possible to do directly in the DB query? Something like a syntactically left-associative XOR operator...
