So I got a View of items in Postgres that looks like this:
| id | brand_id | category_id | color_id | material_id | pattern_id | style_id |
|---|---|---|---|---|---|---|
| 1 | 100 | 101 | 100 | 101 | null | 101 |
| 1 | 100 | 101 | 101 | 102 | null | 102 |
| 2 | 101 | 101 | 102 | 103 | 102 | null |
| 2 | 101 | 101 | 102 | 103 | 103 | null |
| 3 | 105 | 101 | null | 103 | 104 | null |
| 4 | 101 | 101 | 102 | 103 | 103 | 105 |
I need all DISTINCT possible combinations (excluding item_id) but forming groups that not always will include all columns.
Example of combinations for the First Row (but I need the same for all items without getting duplicated groups):
| brand_id | category_id | color_id | material_id | pattern_id | style_id |
|---|---|---|---|---|---|
| 100 | null | null | null | null | null |
| null | 101 | null | null | null | null |
| null | null | 100 | null | null | null |
| null | null | null | 101 | null | null |
| null | null | null | null | null | 101 |
| 100 | 101 | null | null | null | null |
| 100 | null | 100 | null | null | null |
| 100 | null | null | 101 | null | null |
| 100 | null | null | 101 | null | null |
| 100 | null | null | 101 | null | 101 |
| 100 | 101 | 100 | null | null | null |
| 100 | 101 | null | 101 | null | null |
| 100 | 101 | null | null | null | 101 |
I tried a CROSS JOIN with the original categories tables but I get a enormous table of combinations and also I don't get the groups of 1, 2, 3, 4 or 5 categories, I get the combinations including ALL six categories