-3

Good morning. I would like to concatenate may rows into a single text string having 2 tables

Table1

ID   Use
1    A
1    A
1    B
2    A
2    B
2    C
2    B

Table2

ID   Cod_Sig
1    Nat
2    Nono

I would like to have a result like this:

Cod_Sig  Uso
Nat      A, B
Nono     A, B, C

Can anyone help me? Thanks.

Harshil Doshi
  • 3,497
  • 3
  • 14
  • 37

1 Answers1

0

If you are using Mysql then following query will work:

select 
  t2.cod_sig,
  group_concat(distinct t1.use 
               order by t1.use
               separator ',') as uso
from Table1 t1
inner join Table2 t2
on t1.id = t2.id
group by t2.cod_sig

Click here for Demo

Hope it helps!

Harshil Doshi
  • 3,497
  • 3
  • 14
  • 37