1

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 images.id FROM images (id, tagid, imageid) VALUES(tagid || images.id, tagid, images.id);

1 Answer 1

2

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' || images.id, 'tagid', images.id FROM images; 
Sign up to request clarification or add additional context in comments.

1 Comment

Thanks, this much simpler And here I ended up creating a function with a for loop.

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.