Say you have a table like this:
ID | Type | Reference #1 | Reference #2
0 | 1 | [A] | {a}
1 | 2 | [B] | {b}
2 | 2 | [B] | {c}
3 | 1 | [C] | {d}
4 | 1 | [D] | {d}
5 | 1 | [E] | {d}
6 | 1 | [C] | {e}
Is there any good way to group by “Reference #1” and “Reference #2” as a “fallback”, for lack of a better way of putting it…
For example, I would like to group the following IDs together:
{0} [Unique Reference #1],
{1,2} [Same Reference #1],
{3,4,5,6} [{3,4,5} have same Reference #2 and {3,6} have same Reference #1]
I am at a total loss as to how to do this… Any thoughts?
In mellamokb’s query, the groupings are dependent on the order of the input.
ie.
produces a different result tahn
This might be intended, if there is some natural order to the References that you could specify, but its a problem if they are not. The way to ‘solve’ this or specify another problem is to say that all equal Reference1s create a set of elements whose members are themselves and those elements whose Reference2 is equal to at least one member of that set.
In SQL:
This should produce the full grouping each time.