dh1sbg
dh1sbg

Reputation: 15

mysql Main and detail tables with detail data being "joined"

I have two tables, Main and detail with are linked togeather. The output would be somethink like this:

Records found: 8 
mail.field  detail.Field
A               x
A               y
A               z
B               i
B               j
C               l
C               m
C               n

Is it possible to "concat" all detail-Valus to geht this result

Records found: 3

A       x+y+z
B       i+j
C       l+m+m

Upvotes: 1

Views: 27

Answers (2)

dh1sbg
dh1sbg

Reputation: 15

select main_field, group_concat(detail.Field order by detail.Field SEPARATOR '+')
from tablename
JOIN .....
group by main_field

Upvotes: 0

Fahmi
Fahmi

Reputation: 37483

You can use group_concat()

select main_field, group_concat(detail.Field order by detail.Field SEPARATOR '+')
from tablename
group by main_field

Upvotes: 3

Related Questions