I have MySql (8.0) with two tables, main:
ID | TITLE | kindof
1 | aaa | shop
2 | bbb | food
3 | ccc | market
category:
ID | TITLE | CATEGORY
1 | aaa | design, home, clothing
2 | bbb | asian, indian
3 | ccc | second hand
my node/express (main ID is auto increment):
let sql = BEGIN; INSERT INTO main (title,kindof) VALUES("${[req.body.title]}","${req.body.kindof}); INSERT INTO categories (id,title,category) VALUES(LAST_INSERT_ID(),"${[req.body.title]}"," ${[req.body.categories]}"); COMMIT;;
I would like to have:
ID | TITLE | CATEGORY
1 | aaa | design
1 | aaa | home
1 | aaa | clothing
2 | bbb | asian
2 | bbb | indian
3 | ccc | second hand
req.body.category looks like that: {design, home, clothing}
How can I split the string using the comma in MySQL? Thanks