I am inserting data into a database that looks like this:
(1, 'blue'), (2,'large'), (3, 'round')
The numbers there correspond to ID’s from another table. that looks like: id | value
When inserting this data I want to insert the actual value that the number corresponds to, not the id.
Is there any query to do this? or do I need match the values before sending it to the database?
While I know it won’t work, I am hoping there is something like:
insert into table2 (table1.value[id=1], 'blue'), (table1.value[id=2],'large'), (table1.value[id=3], 'round') join table1
I imagine I could use:
insert into table2
((select value from table1 where id=1), 'blue'),
((select value from table1 where id=2),'large'),
((select value from table1 where id=3), 'round')
But with say, 40 different attributes that would make 41 queries!
First virtually make up a table with the values you want to insert (id,value), then join the derived table to table1 and INSERT the result into table2.