-1

I am trying to pull data from multiple cells into one. A device can be in multiple device groups and device groups can have multiple devices.

The first table looks as follows:

First table

The second table looks as follows:

Second table

The output should look as follows:

DID | DGID
12  | 342,543,100,132
45  | 342,678,987,100

Could someone please assist me with this?

Cid
  • 14,968
  • 4
  • 30
  • 45
  • 2
    Serializing datas goes against the purpose of using a RDBMS and you'll have to do the opposite operation to handle datas, deserializing – Cid Jan 15 '20 at 08:07
  • 1
    Does this answer your question? [Can I concatenate multiple MySQL rows into one field?](https://stackoverflow.com/questions/276927/can-i-concatenate-multiple-mysql-rows-into-one-field) – Eriks Klotins Jan 15 '20 at 08:07

1 Answers1

0

Yes. Use GROUP BY and concatenation functions. If this is that useful is another question.

Example:

SELECT 
  did,
  GROUP_CONCAT(dgid SEPARATOR ', ') as dgid
FROM
  table1
  LEFT JOIN table2
GROUP BY
  did

See https://www.geeksforgeeks.org/mysql-group_concat-function/

Paflow
  • 2,030
  • 3
  • 30
  • 50