I'd like to group by 2 columns but in "or mode"... I think I'll explain myself better with an example:
ID | Col 1 | Col 2 | Col 3 | Rest of columns ...
-------------------------------------------------------
1 A Q green
2 B R blue
3 B S red
4 C T purple
5 D U orange
6 E R black
7 F U brown
8 F V pink
9 G W white
So ... Grouping by column 1 we have rows 2+3 and 7+8 merged in results Grouping by column 2 we have rows 2+6 and 7+5 merged in results
But I'd like to group between them, so the SQL results (in this case) in 2 rows in output:
- rows 2, 3 and 6 in a group
- rows 5, 7, and 8 in other group
- among other unique rows
Visual explanation of the 1) group:
Visual explanation of the 2) group:
Is this possible in a unique SQL ? Or is it better to handle this data "merging" in programming code ?
So the result selecting a concat of the column 3, could be:
blue,red,black
brown,pink,orange
(and then the rest that are "unique" of the two groupings...)
green
purple
white
So it's like a "by group" but taking in account 2 columns :-P It's difficult to explain, but I hope visual examples talk by their own.
BTW: I'm in MySQL 8 ... no matter which one, if I have to upgrade or change, I can do it ;-)