I have a table with the following simplified data:
PK FK Type
----------------
1 11 A
2 11 B
3 12 B
4 13 C
5 13 D
6 14 D
And I want a result set of:
PK FK Type
---------------
1 11 A
3 12 B
4 13 C
6 14 D
So if a given FK value has a Type A, don’t give me any rows with B, C, or D. Or if the value has a Type B, then filter out C and D, etc. This feels like I need to apply a window function or coalesce, but I’m not sure how to do it.
Use:
…or using CTE (no performance difference):
Proof:
Result: