Mysql 我的SQL子查询返回超过1行

Mysql 我的SQL子查询返回超过1行,mysql,sql-server,Mysql,Sql Server,我的SQL-> 在这方面,我犯了错误 错误]1242-子查询返回的行数超过1行 是否有其他方法可以实现相同的功能?您的内部查询返回的值超过1个。这将起作用,因为我已将内部查询结果限制为1,但我不确定是否满足您的要求 insert into table b (col list) select id, Col2 = ( select col from (select col from table B where col5 = 'true' limit 0,1) as alias ),

我的SQL->

在这方面,我犯了错误

错误]1242-子查询返回的行数超过1行


是否有其他方法可以实现相同的功能?

您的内部查询返回的值超过1个。这将起作用,因为我已将内部查询结果限制为1,但我不确定是否满足您的要求

 insert into table b (col list)
  select id,
   Col2 = ( select col from (select col from table B where col5 = 'true' limit 0,1) as alias  ),
   Col3 = ( select col from (select col from table B where col4 = 'true'  limit 0,1) as alias 2)
 from table a

错误消息告诉一切,您尝试从子查询传递多个值Col2和/或Col3。您可以告诉我您的表结构和一些数据吗?您已经将其标记为MySql和Sql Server,不能两者都是…您可以始终添加
限制1
(MySql)或
顶部1
(mssql)但我首先会问自己这是否正确。我不想插入0或1,如果它为真,我必须插入另一列值,然后是col1或“”,它必须是一对一的映射。使用if-else作为Col2=(选择if(col1=“abc”,col1,”);如果col1有值abc,这将返回col1
 insert into table b (col list)
  select id,
   Col2 = ( select col from (select col from table B where col5 = 'true' limit 0,1) as alias  ),
   Col3 = ( select col from (select col from table B where col4 = 'true'  limit 0,1) as alias 2)
 from table a