MySQL: Output rows created from columns containing delimited data

196 views Asked by At

Assuming I have the following data in a MySQL:

**bond** | **node** | **edges**
foo      |    1     |    2,3
hak      |    2     |    1
wat      |    3     |    1,2

I wish to return results to create data suitable for visualisation in Cytoscape. It requires that each node have a line devoted to each edge. The output would look like:

**bond** | **node** | **edges**
foo      |    1     |    2
foo      |    1     |    3
hak      |    2     |    1
wat      |    3     |    1
wat      |    3     |    2

I think the PIVOT operator might work somehow, but I have had no luck.

1

There are 1 answers

1
Akhil On BEST ANSWER

Assuming you have an edge master table where in all possible values for edges are stored.

If my assumption is wrong, my answer will not hold good

SELECT bond, node, edgemaster.edgeid FROM mytable
JOIN edgemaster ON FIND_IN_SET(edgemaster.edgeid, mytable.edges)
ORDER BY bond, node, edgemaster.edgeid

Sql Fiddle