Ask the Expert

What is the difference between left outer join and (+) outer join?

What is the difference between left outer join and (+) outer join? When I use left outer join the cost of the SQL query is high, and when I use the (+) operator the join cost is much less.

    Requires Free Membership to View

There are three types of outer joins, left, right and full. A left outer join contains all records of the "left" table even if it has no matches in the "right" table specified in the join. A right outer join contains all records in the "right" able even if it has no matches in the "left" table. A full outer join contains all records of both the left and right tables.

In ANSI SQL 92 syntax, you specify a left outer join with the LEFT OUTER JOIN operand in your SQL statement. So a left outer join in SQL 92 syntax might look like the following:

SELECT x.id, x.colZ, y.colA
FROM x LEFT OUTER JOIN y ON x.id=y.id;

Before Oracle supported this syntax, you used the "(+)" operator to define an outer join. To perform the left outer join example above with the "(+)" operator, the SQL statement would look like:

SELECT x.id, x.colZ, y.colA
FROM x, y  WHERE x.id=y.id(+); 

You can easily change the above to a right outer join by moving the outer join operator as follows:

SELECT x.id, x.colZ, y.colA
FROM x, y  WHERE x.id(+)=y.id; 

You should not be experiencing performance differences with the differences in notating the left outer join, provided your query is written properly. Ensure you have the WHERE clause instead of the ON clause when using the older outer join notation. Otherwise, you might have to file a bug report with Oracle Support.

This was first published in June 2007

There are Comments. Add yours.

 
TIP: Want to include a code block in your comment? Use <pre> or <code> tags around the desired text. Ex: <code>insert code</code>

REGISTER or login:

Forgot Password?
By submitting you agree to receive email from TechTarget and its partners. If you reside outside of the United States, you consent to having your personal data transferred to and processed in the United States. Privacy
Sort by: OldestNewest

Forgot Password?

No problem! Submit your e-mail address below. We'll send you an email containing your password.

Your password has been sent to: