I have an SQL table with three columns X, Y, Z. I need to split it into groups so that all records with the same X or Y or Z value are assigned to the same group. I need to make sure that records with the same value of X or Y or Z never break into multiple groups.
If you consider records as nodes and X, Y, Z values as edges, this problem is the same as finding all the graphs, where the nodes in each graph will be connected directly or indirectly via X, Y or Z-edge, but each graph will not have any edges along with other graphs (otherwise it will be part of the same graph).
A few years ago, I knew that it was called and even remembered the algorithm, but now it eludes me. Please tell me how this problem is called so that I can find a solution to Google. If you have a good algorithm now, please indicate it to me. If you have a SQL implementation - I will marry you :)
Example:
XYZ BUCKET --------- ---------------- --------- ----------- 1 34 56 1 54 43 45 2 1 12 22 1 2 34 11 1
The last row is in bucket 1 because of the value Y = 34, which matches the value of the first row, which is in bucket 1.
source share