如何使用子查询作为插入值?
How to use a sub-query as value for inserting?
我有这样的查询:
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);
但是第二个查询不起作用,我该如何解决?
INSERT INTO table1(col1, col2, col3, col4)
select 1, col1, col2, 1
from table2
where col2 = :param;
我有这样的查询:
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);
但是第二个查询不起作用,我该如何解决?
INSERT INTO table1(col1, col2, col3, col4)
select 1, col1, col2, 1
from table2
where col2 = :param;