5

i need to perform a insert query for multiple rows whereby the first column is a numeric and identical value and the second values are queried from another table.

something like

insert into table (33, select col2 from another_table);

can this be accomplished with a single statement?

2 Answers 2

13

like this

insert into table 
select 33, col2 from another_table;
Sign up to request clarification or add additional context in comments.

2 Comments

in this example, the table being inserted must have only two fields: one that will receive the numeric and another of the same type as col2 from another_table
I was wondering if there was a possibility to specify columns explicitly like: insert into table (id, col2_name) values((select 33, col2 from another_table)) ?
1

If you want to specify columns in your insert query, you should use this syntax:

INSERT INTO table (id, col2_name) (SELECT 33, col2 FROM another_table);

Comments

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.