1

I have a table where two columns are comma separated id's. For example

+--------+-------------+------------+
| name   | country_ids | region_ids |
+--------+-------------+------------+
| item 1 | 1,2,3       | 2,4        |
+--------+-------------+------------+
| item 2 | 2,3         | 1,4        |
+--------+-------------+------------+

I would like to run a mysql query so the comma separated values in both columns are split into multiple rows. So in the above example, the results would be

name     | country_id | region_id |
+--------+------------+-----------+
item 1   |  1         |  2        |
item 1   |  1         |  4        |
item 1   |  2         |  2        |
item 1   |  2         |  4        |
item 1   |  3         |  2        |
item 1   |  3         |  4        |
item 2   |  2         |  1        |
item 2   |  2         |  4        |
item 2   |  3         |  1        |
item 2   |  3         |  4        |

Is this possible in a mysql statement - even if I have to create a stored procedure on the fly?

THanks

Typhoon101
  • 2,063
  • 8
  • 32
  • 49

0 Answers0