首页 > 解决方案 > 检索子查询中导致“单行子查询返回多行”的特定行

问题描述

我有一个查询,其中嵌套子查询引发错误“单行子查询返回多行”。此错误发生在一个环境中。(TEST) 但不是另一个 (STAGE),因为存在一些数据差异。

我需要找出究竟是哪些数据导致了这种情况。但是如何将其重写为 WHERE/HAVING COUNT > 0 查询?子查询是嵌套的。

假设PLANS_T.MANAGER_ID是我在PERSON_T下面的子查询中检查的“外部”值。

select * from plans_t p 
where 
(select inactive_date 
from persons.person_t 
where 
current_flag = 'Y' and 
uniqueidentifier = p.manager_id
) is null

这是在甲骨文中。

标签: sqloracle

解决方案


尝试

select inactive_date 
from persons.person_t 
where 
current_flag = 'Y' and 
uniqueidentifier in (select p.manager_id from plans_t p)
group by inactive_date 
having count(*)>1

推荐阅读