da1lbi3
da1lbi3

Reputation: 4519

Link tables together

I want to link 2 tables togheter, but my second table has more than one value.

First table:

Partnumber | description | type
100          blabla        blabla

second table:

Partnumber | item number
100          500
100          600
200          0

now i want to link the tables together on partnumber but all the item numbers must go in the same record. and there can be more item numbers on a part number.

result:

partnumber | description | type    | item number
100          blabla        blabla    500,600

is it possible to show it that way? in one line?

thank you very much!

Upvotes: 0

Views: 21

Answers (1)

Jean-François Savard
Jean-François Savard

Reputation: 21004

you want to use the group_concat function

select partnumber, description, type, group_concat(coalesce(item_number, "No items"))
from table1 a
left join table2 b using(partnumber)
group by partnumber;

Upvotes: 1

Related Questions