Mysql 通过子查询插入多行

Mysql 通过子查询插入多行,mysql,subquery,bulkinsert,multiple-records,Mysql,Subquery,Bulkinsert,Multiple Records,我试图使用子查询插入多行,但它给出了错误“子查询返回多行” 场景是,我想对子部门的每个测试添加注释,我通过子查询获得所有测试id,但我无法迭代id并对每个测试插入注释。这是我的SQL查询 INSERT INTO dc_tp_comment (labid,branchid,Comment,testid,lastupdated,enteredby) Values('abcd',101,'comment here',(select T.testid from dc_tp_test T Inner J

我试图使用子查询插入多行,但它给出了错误“子查询返回多行”

场景是,我想对子部门的每个测试添加注释,我通过子查询获得所有测试id,但我无法迭代id并对每个测试插入注释。这是我的SQL查询

INSERT INTO dc_tp_comment  (labid,branchid,Comment,testid,lastupdated,enteredby)
Values('abcd',101,'comment here',(select T.testid
from dc_tp_test T
Inner Join dc_tp_subdepartments S
on T.subdepartmentid = S.subdepartmentid
Where S.subdepartmentid = 13),sysdate(),1)

如果要插入多行,请使用“选择替代值…”

语法如下:

INSERT INTO dc_tp_comment  (labid,branchid,Comment,testid,lastupdated,enteredby)
select 'abcd',101,'comment here',(select T.testid
from dc_tp_test T
Inner Join dc_tp_subdepartments S
on T.subdepartmentid = S.subdepartmentid
Where S.subdepartmentid = 13),sysdate(),1

不能仅在一列中使用subselect,请将其用于整行:

INSERT INTO dc_tp_comment  (labid,branchid,Comment,testid,lastupdated,enteredby)
select 'abcd',101,'comment here', T.testid, sysdate() , 1
from dc_tp_test T Inner Join dc_tp_subdepartments S
on T.subdepartmentid = S.subdepartmentid
Where S.subdepartmentid = 13
返回相同错误“子查询返回1行以上”