Sql 插入语句中,插入的某个字段可以通过查询语句获得的方法

例如需要插入如下语句:

Insert into a (a1,a2,a3) values (1,select num from b where id=1,3) 

其中num字段是可以通过select num from b where id=1 查询得到

这样select语句出现在赋值语句中是不允许的。报错为"只允许出现标量表达式" 

可以这样:

insert into a (a1,a2,a3) select 1,num,3 from b where id=1 

即可解决

原文地址:https://www.cnblogs.com/zhouchuansong/p/6595083.html