2

I got these three tables s,a and p. a and s got 1:1 relation. But a to p got 1:x relation. My current query is only build for 1:0 or 1:1 relation. Currently I'm getting: "ORA-01427: single-row subquery returns more than one row." If there's more than one resource_id for an activity_no

So how do I redo my query so If there's two or more resource_id for an activity_id I want to duplicate the selected row two or more times depending on how many resource_id there is for an activity_no?

I've been looking on: Oracle, insert multirows from subquery with more than one row but It doesn't work.

    select s.sub_project_id,  
           a.activity_no,
           (select p.resource_id
            from p
            where p.project_id = 'PROPSTOT'
            and p.activity_seq = a.activity_seq,                                     
from s,
     a
where s.sub_project_id = a.sub_project_id
      and s.project_id = 'PROPSTOT' 
      and a.project_id = 'PROPSTOT'
4

2 回答 2

2

尝试加入查询中的表,如下所示:

select s.sub_project_id,  
       a.activity_no,
       p.resource_id
from s
join a on s.sub_project_id = a.sub_project_id and a.project_id = 'PROPSTOT'
left join p on p.project_id = 'PROPSTOT' and p.activity_seq = a.activity_seq
where s.project_id = 'PROPSTOT' 
于 2013-06-05T10:26:18.483 回答
1

我不清楚你到底想做什么,但从你的描述来看,你只是想加入:

select s.sub_project_id,  
       a.activity_no,
       p.resource_id
from s 
   join a on s.sub_project_id = a.sub_project_id and a.project_id = s.project_id
   left outer join p on p.activity_seq = a.activity_seq
where s.project_id = 'PROPSTOT' 
于 2013-06-05T10:27:44.710 回答