5

I have the following queries:

    insert into TABLE1(a,b,c,d) VALUES('first','second','third',100);
    insert into TABLE1(a,b,c,d) VALUES('first','second','third',101);
    insert into TABLE1(a,b,c,d) VALUES('first','second','third',102);
    insert into TABLE1(a,b,c,d) VALUES('first','second','third',103);

colums a,b and c would always have same values across all rows. I got 100,101,102 and 103 from a select statement from another table.

    select id from TABLE2;        //returns (100,101,102,103).

Can I do this using a single query?

1 Answer 1

13

The following query allows you to insert multiple rows based on the results of a query on another table.

INSERT INTO TABLE1 (a, b, c, d) SELECT 'first', 'second', 'third', id FROM TABLE2;
Sign up to request clarification or add additional context in comments.

2 Comments

Good first SQL answer Ken. Welcome to Stack
@Twelfth Thanks!

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.