2015-06-26 41 views
4

假設我有`table1(col1,col2,col3),在col1和col3上插入的值將是相同的,但在col2上插入的值來自一個選擇查詢。從select中插入多行到另一個表中

我該如何編寫我的查詢,以便我可以一次執行多次插入?的查詢應該做些什麼 例子:

col1 | col2 | col3 

1  val1  0 
1  val2  0 
1  val3  0 

回答

11

如果我理解正確的話,你可以使用insert . . .select

insert into table1(col1, col2, col3) 
    select 1, col2, 0 
    from <your other query here>; 
相關問題