oracle - SQL Query - Multiple Joins -
i'm having difficulty in joining same table(s) twice because of results returned incorrect.
the query below works fine. however, want change can return column of requirement type
using value returned in requirement traced to
column.
select r.rq_req_id "requirement traced from", r.rq_req_name "requirement name", rty.tpr_name "requirement type", rtr.rt_to_req_id "requirement traced to" req r left join req_trace rtr on r.rq_req_id = rtr.rt_from_req_id, req_type rty r.rq_type_id = rty.tpr_type_id , rty.tpr_name in ('tom', 'business process map', 'work instruction', 'functional', 'customer journey', 'business') order 1
when add req
, req_type
tables in second time different aliases hundreds of rows returned instead of 28 expecting.
any appreciated.
never use commas in from
clause. always use explicit join
syntax.
you need add additional joins this:
select r.rq_req_id "requirement traced from", r.rq_req_name "requirement name", rty.tpr_name "requirement type", rtr.rt_to_req_id "requirement traced to", rty2.tpr_name "requirement type to", req r left join req_trace rtr on r.rq_req_id = rtr.rt_from_req_id left join req_type rty on r.rq_type_id = rty.tpr_type_id left join req r r2 on r2.rq_req_id = rtr.rt_to_req_id left join req_type rty2 on rty2.tpr_type_id = r2.rq_type_id rty.tpr_name in ('tom', 'business process map', 'work instruction', 'functional', 'customer journey', 'business') order 1;
Comments
Post a Comment