i have a table1 Option
ID |option | PreRequisite
-------------------------------------
1 | India | null
2 | Japan | null
3 | China | null
4 | ABC | Q1|1,Q2|2
5 | DEF | Q1|1
6 | KLM | Q1|1
i have another table2
Key | ParentOption |ChildOption
---------------------------------
Q1 | INDIA | EFG
Q1 | INDIA | GHI
Q1 | JAPAN | ABC
Q1 | JAPAN | DEF
Q1 | INDIA | KLM
so i have to merge this 2 tables and which ever child option is not present in table1 ,i have to insert that childoption along with PreRequisite updated to Q1|"ID of parent from the table 1" i.e for "Q1 | India | EFG " the new entry in table 1 should be
ID | option| PreRequisite
----------------------------
7 | EFG | Q1|1
now if the childoption is already there in table1 ,i have to append the parentoption's id from table1 into prerequisite column .
i.e for Q1 | JAPAN | DEF row should get update to
ID |option | PreRequisite
-------------------------------------
1 | DEF | Q1|1|2
for Q1 | JAPAN | ABC row should get update to
ID |option | PreRequisite
-------------------------------------
4 | ABC | Q1|1|2,Q2|2
but for childoption which are already there in the table along with prerequisite filled with Q1|"parentOption's id",nothing should be updated.
for Q1 | INDIA | KLM row should get update to
ID |option | PreRequisite
-------------------------------------
5 | KLM | Q1|1
so the final result should be
ID |option | PreRequisite
-------------------------------------
1 | India | null
2 | Japan | null
3 | China | null
4 | ABC | Q1|1|2,Q2|2
5 | DEF | Q1|1|2
6 | KLM | Q1|1
7 | EFG | Q1|1
8 | GHI | Q1|1