question

dbkid avatar image
dbkid asked

Question on outer join.?

The query is like this.

SELECT * FROM

( select 'A1' as a , 'B1' as b from dual union all

select 'A1' as a , 'B2' as b from dual union all

select 'A2' as a , 'B1' as b from dual

) FIRST,

( select 'A1' as a , 'B1' as b from dual union all

select 'A1' as a , 'B2' as b from dual union all

select 'A3' as a , 'B1' as b from dual

) SECOND

WHERE FIRST.A = SECOND.A(+) AND FIRST.B = SECOND.B

The result I am expecting is 3 rows from the table "First". But its returning only 2 rows. Is there any reason?

sqloracle
10 |1200

Up to 2 attachments (including images) can be used with a maximum of 512.0 KiB each and 1.0 MiB total.

1 Answer

·
Tariq Rahiman avatar image
Tariq Rahiman answered

This query will return only 2 rows since there are only 2 matching rows. If you notice in the last select 'A3' as a , 'B1' as b from dual , if it had been A2, the query would return 3 rows.

SELECT * FROM

(select 'A1' as a , 'B1' as b from dual union all select 'A1' as a , 'B2' as b from dual union all select 'A2' as a , 'B1' as b from dual)FIRST

right outer join

( select 'A1' as a , 'B1' as b from dual union all
select 'A1' as a , 'B2' as b from dual union all
select 'A3' as a , 'B1' as b from dual
) SECOND

ON FIRST.A = SECOND.A and FIRST.B = SECOND.B

The above query gave me 3 rows and is according to the definition of right outer join

2 comments
10 |1200

Up to 2 attachments (including images) can be used with a maximum of 512.0 KiB each and 1.0 MiB total.

dbkid avatar image dbkid commented ·
But I am applying a Right outer join by keeping the condition as FIRST.A = SECOND.A(+). So it should return the thrid row also right? Please correct me if I am wrong.
0 Likes 0 ·
dbkid avatar image dbkid commented ·
Yes this is giving the right answer. But if you see the query which I specified above, I am using (+) symbol for outerjoin. I applied condition as FIRST.A = SECOND.A(+) AND FIRST.B = SECOND.B. So here I didn't put (+) symbol over B. So Just got confused how oracle processes it ? .
0 Likes 0 ·

Write an Answer

Hint: Notify or tag a user in this post by typing @username.

Up to 2 attachments (including images) can be used with a maximum of 512.0 KiB each and 1.0 MiB total.