I have the following result sets:
Those values come from a relational table of
ProductId, GroupId
1 | 4
2 | 4
2 | 5
3 | 4
3 | 5
CategoryId | ProductId
1 | 1
1 | 2
1 | 3
All the following "Id" are from the category of those produtcts
Example 1: Example 2: Example 3:
|Id |Group| |Id |Group | |Id |Group |
----------- --------------- ---------------
| 1 | 4 | | 1 | 4,5 | | 1 | 3,5 |
| 1 | 4,5 | | 1 | 3,4,5,6 | | 1 | 3,4,5,6 |
| 1 | 5,7 | | 1 | 5,7 | | 1 | 4,5 |
----------- --------------- ---------------
I need to process those tables to get the following results
Result 1: Result 2: Result 3:
|Id |Group| |Id |Group | |Id |Group |
----------- --------------- ---------------
| 1 | 4,5 | | 1 | 3,4,5,6 | | 1 | 3,4,5,6 |
| 1 | 4,5 | | 1 | 3,4,5,6 | | 1 | 3,4,5,6 |
| 1 | 5,7 | | 1 | 5,7 | | 1 | 3,4,5,6 |
----------- --------------- ---------------
Explanation for that, those columns indicate where the price of some item should be placed, and all related prices should be in the same table if possible, so when a group can be joined with other it should result in empty spaces for the columns that weren't originally for that product so:
Using example 1 this is the final result:
| G4 | G5 |
--------------------
Product1 | 10 | |
Product2 | | 15 |
Product3 | 14 | 18 |
--------------------
| G5 | G7 |
--------------------
Product1 | 10 | 25 |
Product2 | | 15 |
--------------------
Using the example 3 this is the final result:
| G3 | G4 | G5 | G6 |
------------------------------
Product1 | 10 | | 15 | 20 |
Product2 | | | 17 | |
Product3 | 14 | 18 | | |
------------------------------
But I'm completly clueless on how to do those group joins (the empty spaces in the result set is not a problem.