Hi guys,
I am writing a stored proc and trying to insert table from other table using mapping rules and more complicated thing is the mapping rule is using third table to lookup.
So here's the diagram
table1 (product_code, product_id)
table2 (product_code, product_desc)
table3 (product_id, product_desc)
I would like to insert into table1.product_id from table2.product_desc
but first I need to get the table3.product_id by looking up from table2.product_desc
then insert the table3.product_id into table1.
in sql code I have tried this but not working
Which one is wrong exactly inside my query?
Thank you in advance guys
I am writing a stored proc and trying to insert table from other table using mapping rules and more complicated thing is the mapping rule is using third table to lookup.
So here's the diagram
table1 (product_code, product_id)
table2 (product_code, product_desc)
table3 (product_id, product_desc)
I would like to insert into table1.product_id from table2.product_desc
but first I need to get the table3.product_id by looking up from table2.product_desc
then insert the table3.product_id into table1.
in sql code I have tried this but not working
Code:
insert into table1(product_code,product_id)
select product_code, (select table3.product_id from table2, table3 where table2.product_desc=table3.product_desc)
from table2
Which one is wrong exactly inside my query?
Thank you in advance guys