Assume that we have two data sets A, B that have m to n relationship.
A = { k1, k2, k3 …. kn}
B = { g1, g2, g3……….gn}
All the elements in both the sets are alphanumeric.
Now, tuples one each from Set A and Set B are stored in a table T.
for ex :-
(k1, g2)
(k2, g4)
(k1, g3)
(k4, g2)
…
…
..
(kn, gm)
The challenge is to find out what ‘m’ elements in set A map to what ‘n’ elements in set B in the most efficient way.
For ex, let’s say we have the below tuples,
(k1, g1)
(k1, g2)
(k3, g1)
(k3, g2)
(k5, g1)
(k5, g2)
the o/p I need is (k1, k3, k5) -> (g1, g2).
As the mapping is m to n, a simple select won’ t work. Please let me know if you need further clarifications
Since this information is already in database, I would prefer if we can get to this with some SQL.
Help much appreciated.
Thanks in advance…
You can often solve problems like this by using an aggregate, and a group by clause.
For example, if your table name is T then:
Gives you which item1 maps to item 2. THen do it again switching item1 and item 2 around to find which item2 maps to item1.