首页
学习
活动
专区
圈层
工具
发布
首页
学习
活动
专区
圈层
工具
MCP广场
社区首页 >问答首页 >操作数应包含1列子查询MySQL

操作数应包含1列子查询MySQL
EN

Stack Overflow用户
提问于 2016-04-25 03:58:02
回答 1查看 453关注 0票数 0

当我进行子查询时,我有问题

代码语言:javascript
运行
复制
select r.Request_ID,
(
(select e.ReportsTo, (select e1.FirstName from Employees e1 where e1.NIK = e.ReportsTo) as FirstName, 
(select e1.NIK from Employees e1 where e1.NIK=e.NIK) as Attention, 
(select e1.FirstName from Employees e1 where e1.NIK=e.NIK) as AttentionName 
from Employees e where e.ReportsTo ='CS-NIK-2016-0150' and e.NIK='CS-NIK-2016-0160')
)
from Request r where r.Request_ID='CS-REQ-BDG-201604-10099'

操作数应该包含1列,为什么?

EN

回答 1

Stack Overflow用户

发布于 2016-04-25 04:41:57

使用联接而不是子查询。此外,您的子查询可能返回多于1行,因此它会显示错误。为了避免对每个select的错误使用限制(这不是最好的解决方案),在这种情况下,它只返回第一行。

代码语言:javascript
运行
复制
select r.Request_ID,
(
(select e.ReportsTo, (select e1.FirstName from Employees e1 where e1.NIK = e.ReportsTo limit 1) as FirstName, 
 e.NIK as Attention, FirstName as AttentionName 
from Employees e where e.ReportsTo ='CS-NIK-2016-0150' and e.NIK='CS-NIK-2016-0160')
)
from Request r where r.Request_ID='CS-REQ-BDG-201604-10099'
票数 0
EN
页面原文内容由Stack Overflow提供。腾讯云小微IT领域专用引擎提供翻译支持
原文链接:

https://stackoverflow.com/questions/36831798

复制
相关文章

相似问题

领券
问题归档专栏文章快讯文章归档关键词归档开发者手册归档开发者手册 Section 归档