I have two tables.
REJECT_REASONS
Account_No | Resn_Id1 | Resn_Id2 | Resn_Id3 | Resn_Id4 |
---|---|---|---|---|
100 | 0001 | 0005 | 0006 | 0104 |
101 | 0005 | 0006 | 0104 | |
102 | 0001 | 0006 | ||
103 | ||||
104 | 0001 |
REASON_DESC
Resn_Id | Resn_Desc |
---|---|
0001 | Bad Account |
0005 | Duplicate Account |
0006 | Invalid Data |
0104 | Invalid address |
I want to join the table REJECT_REASONS with REASON_DESC on each of the columns resn_id1, resn_id2, resn_id3 and resn_id4 with resn_id and get resn_desc in the result.
I tried the below query:
select r.account_no,r.resn_id1,rd1.resn_desc,
r.resn_id2,rd2.resn_desc,
r.resn_id3,rd3.resn_desc,
r.resn_id4,rd4.resn_desc
from reject_reasons r, reason_desc rd1, reason_desc rd2, reason_desc rd3, reason_desc rd4
where r.resn_id1=rd1.resn_id(+)
and r.resn_id2=rd2.resn_id(+)
and r.resn_id3=rd3.resn_id(+)
and r.resn_id4=rd4.resn_id(+)
;
Desired Output: |Account_no | Resn_Id1 | Resn_desc1 | Resn_Id2 | Resn_desc2 | Resn_Id3 | Resn_desc3 | Resn_Id4 | Resn_desc4 |
Please let me know if there is a way to simplify the query.