7

let's say i have `table1(col1,col2,col3), the values to insert on col1 and col3 will be the same, but the values to insert on col2 come from the result of a select query.

How can i write my query so i can do this multiple insert at once ? Example of what the query should do :

col1  |  col2   | col3

 1        val1     0
 1        val2     0
 1        val3     0

1 Answer 1

21

If I understand correctly, you would use insert . . .select:

insert into table1(col1, col2, col3)
    select 1, col2, 0
    from <your other query here>;
Sign up to request clarification or add additional context in comments.

2 Comments

Can we add Where clauses in the select query here, because sometimes we may want to use only certain rows of second table ?
@DhumilAgarwal . . . Yes, you can add a where clause to the select.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.