Tek-Tips is the largest IT community on the Internet today!

Members share and learn making Tek-Tips Forums the best source of peer-reviewed technical information on the Internet!

  • Congratulations strongm on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

Query Re-write

Status
Not open for further replies.

rasprer

Programmer
Feb 12, 2004
102
US
Fellows...Any other way I can rewrite this outer join query.

select a.id
from app a, account b
where a.id = b.id(+)
 
Yes,

Here are some sample data to fit your scenario:
Code:
select * from app;

        ID
----------
         1
         3

select * from account;

        ID
----------
         1
         4

To obtain the same results as your code, you can specify any of these four syntax choices (in Oracle 9i):
Code:
select a.id
from app a, account b
where a.id = b.id(+);

        ID
----------
         1
         3

select a.id
from app a, account b
where b.id(+) = a.id;

        ID
----------
         1
         3

select a.id
from app a left outer join account b
on a.id = b.id;

        ID
----------
         1
         3

select a.id
from account b right outer join app a
on a.id = b.id;

        ID
----------
         1
         3

The neat, new feature of Oracle 9i is its support for "full outer joins":
Code:
select a.id a_id, b.id b_id
from account b full outer join app a
on a.id = b.id;

      A_ID       B_ID
---------- ----------
         1          1
                    4
         3

Let us know if this answers your question.

[santa]Mufasa
(aka Dave of Sandy, Utah, USA)
@ 01:12 (23Feb05) UTC (aka "GMT" and "Zulu"),
@ 18:12 (22Feb05) Mountain Time
Do you use Oracle and live or work in Utah, USA? Then click here to join Utah Oracle Users Group on Tek-Tips.
 
Mufasa....This is great. Thank you. On my original query, it seemed as if I was still doing a full table scan per the Explain Plan. It is my understanding that a full table scan will not utilize the appropriate indexes. Am I correct? This is the reason why I needed any other .sql suggestions that my eliminate a full scan.
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top