I need to group the result when there are equal records, regardless of order, whenever the same colors are chosen - group colors and users together. I need to produce an output like the one below:
0 => array( 'cores' => 'azul, verde' , 'user' => '1, 3' )
1 => array( 'cores' => 'azul' , 'user' => '2' )
// Usuarios 1 e 3 escolheram azul e verde
// Usuario 2 escolheu azul
My table
TABELA.ESCOLHA TABELA.CORES
ID | USER ID | ESCOLHA | CORES
--------- ---------------------
1 | 1 1 | 1 | azul
2 | 2 2 | 1 | verde
3 | 3 3 | 2 | azul
4 | 3 | azul
5 | 3 | verde
My query
select
group_concat( user ) user
, group_concat( cores ) cores
from escolha
inner join cores
on cores.escolha = escolha.id
group by user
I tried group by user
, tried other fields, but did not work as expected.