Insert into … values ( SELECT … FROM … )

前端 未结 26 2433
我在风中等你
我在风中等你 2020-11-21 05:40

I am trying to INSERT INTO a table using the input from another table. Although this is entirely feasible for many database engines, I always seem to struggle t

26条回答
  •  傲寒
    傲寒 (楼主)
    2020-11-21 05:56

    To add something in the first answer, when we want only few records from another table (in this example only one):

    INSERT INTO TABLE1
    (COLUMN1, COLUMN2, COLUMN3, COLUMN4) 
    VALUES (value1, value2, 
    (SELECT COLUMN_TABLE2 
    FROM TABLE2
    WHERE COLUMN_TABLE2 like "blabla"),
    value4);
    

提交回复
热议问题