带子查询的左外连接?
----------
User
----------
user_ID(pk)
UserEmail
----------
Project_Account
----------
actno
actname
projno
projname
ProjEmpID
ProjEmpMGRID
其中 ProjEmpID、ProjEmpMGRID 是 user_id,ProjEmpMGRID 可以为 null。 我需要查找 userremail 并显示表 project_account。我需要使用有重复值的 actNo 进行查询。
我的查询如下:
select projno,projname,actno,actname,
(select u.user_email as project_manager from project_account c left outer join users u
on u.user_id = c.ProjEmpID where actno='some no')as project_manager,
(select u.user_email as program_manager from project_account c left outer join users u
on u.user_id = c.ProjEmpMGRID where actno='someno') as program_manager
from project_account where actno='someno'
我在 Oracle 中收到的错误消息:
ora-01427 单行子查询返回 超过一行
由于我的子查询返回多个电子邮件 ID,我收到此错误。正如我所说,“不行动”并不是独一无二的。我可以理解该错误,但无法找出解决方案。我正在子查询中执行左外连接,因为 prog manager id 中可能存在空值。
任何帮助将不胜感激。
----------
User
----------
user_ID(pk)
UserEmail
----------
Project_Account
----------
actno
actname
projno
projname
ProjEmpID
ProjEmpMGRID
Where ProjEmpID,ProjEmpMGRID is the user_id and ProjEmpMGRID can be null.
I need to look up the useremail and display the table project_account. I need to query with actNo which has duplicate values.
My query goes like this:
select projno,projname,actno,actname,
(select u.user_email as project_manager from project_account c left outer join users u
on u.user_id = c.ProjEmpID where actno='some no')as project_manager,
(select u.user_email as program_manager from project_account c left outer join users u
on u.user_id = c.ProjEmpMGRID where actno='someno') as program_manager
from project_account where actno='someno'
The error message I get in Oracle:
ora-01427 single row subquery returns
more than one row
As my subquery returns more than one email id, I get this error. As I said, act no is not unique. I could understand the error, but I couldn't figure out the solution. I am doing a left outer join in a subquery because there might be nulls in prog manager id.
Any help would be appreciated.
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(3)
您收到的错误是您的子查询之一(针对project_manager 或program_manager)根据您的条件返回多个ID。这是有道理的,因为多个项目帐户可能具有相同的“actno”,因为您没有
进一步将其指定为 Primarky Key (pk),而不是使用子查询,只需直接联接到用户表来查找 ID
The error you are getting is that one of your subqueries (either for project_manager or program_manager) is giving you back more than one ID based on your conditions. This kind of makes sense, since multiple project accounts could have the same "actno" since you haven't specified that as a Primarky Key (pk)
furhter, rather than using subqueries, just join directly to the user tables to find the IDs
怎么样:
这样您就不会运行子查询并返回多个结果并尝试将它们存储为一个值。
What about something like:
This way you aren't running subqueries and returning multiple results and trying to store them as one value.
你为什么不简单地使用这个呢?
选择 projno、projname、actno、actname,(从 user_id = pa.projempid 的用户中选择 user_email),(从 user_id = pa.projempmgrid 的用户中选择 user_email)
来自project_account pa
Why don't you simply use this?
select projno, projname, actno, actname, (select user_email from users where user_id = pa.projempid), (select user_email from users where user_id = pa.projempmgrid)
from project_account pa