I have a requirement to insert / update rows in a table based on information in the other table. I will illustrate my requirement below by providing an example.
Below table is where I want to update / insert data based on data existing in the table table Name tab1
tab1_id | tab1_question_id | tab1_sectorID | tab1_NC_id
1 | 101 | 11 | 21
Below table is where I want to copy the data and import it to the table tab1
tab2_id | tab2_question_id | tab2_sectorID | tab2_NC_ids |import_complete
1 | 101 | 11 | 21,22,23 | 0
2 | 102 | 11 | 22,23,24 | 0
3 | 103 | 11 | 22,24,25 | 0
- The tab2_NC_ids have values of different NC's seperated by commas. Now I am trying to insert these values in tab1 table.
- For instance in tab1 question_id 101 and NC_id 21 is already existing. So that row shouldn't be duplicated with same question_id and NC_id
- I want to split the NC_ids from tab2 and insert/update each row based on data existing in tab1.
In this question I am not just trying to split the values, but also split them and assign values to the new table with relations kept intact and this has to be done dynamically.
How can I achieve this. I am trying to create a stored procedure in MySQL for the above but haven't found any possible solution because of NC_ids is concatenated with a comma. Any help would be great, thanks.