Search code examples
mysqlbulkinsert

MYSQL bulkinsert: multi insert with value into a select


I have a question about the multi-ing (bulk) insert with mysql..

I know that:

INSERT INTO "my_table" ('col1','col2','col3') VALUES 
(1,1,1),(2,2,2);

But I need to do something like:

INSERT INTO "my_table" ('col1','col2','col3') VALUES
((SELECT select1 as col1,select2 as col3 from "my_table2"),"textForAllCol2")

Where my select return a list of 2 column.

I'M trying to explain the best i can..

Thanks for your help!

JP


Solution

  • Here is referenced SQLFiddle for you

    Modify your query as

    INSERT INTO my_table SELECT col1, "textForAllCol2", col2 FROM my_table2;