TheDarkVoid TheDarkVoid - 1 year ago 92
SQL Question

SQL: Using data from one table to insert new data into another table

I am trying to write a query to create a row in a table "tagmap" which will use a constant value "tagid" and the "id" of a row in table images. I want this to be done for each row in the other table.

I've tried quite a few things but essentially this is what I want to end up with:

INSERT INTO tagmap SELECT FROM images (id, tagid, imageid) VALUES(tagid ||, tagid,;

dmg dmg
Answer Source

All you have to do is project the values you want to insert. No need for "values" when you are using select:

INSERT INTO tagmap(id, tagid, imageid) 
  SELECT 'tagid' ||, 'tagid', FROM images; 
Recommended from our users: Dynamic Network Monitoring from WhatsUp Gold from IPSwitch. Free Download