2016-01-07 23 views
1

我有一個這樣的查詢:如何使用子查詢作爲插入的值?

INSERT INTO table1(col1,col2,col4) 
      VALUES (1, (select col1 from table2 where col2 = :param), 1); 

上面的查詢工作爲好。現在我想用兩列從table2,就像這樣:

INSERT INTO table1(col1,col2,col3,col4) 
      VALUES (1, (select col1,col2 from table2 where col2 = :param), 1); 

但第二個查詢不工作,我該如何解決呢?

回答

3
INSERT INTO table1(col1, col2, col3, col4) 
select 1, col1, col2, 1 
from table2 
where col2 = :param; 
+0

完美...! +1 – Shafizadeh