This question already has answers here:
Oracle "(+)" Operator
(4 answers)
How to find LEFT OUTER JOIN or RIGHT OUTER JOIN with ORACLE JOIN (+)
(2 answers)
Closed 7 years ago.
I'm quite new to oracle sql and just ran into a query that looks something like this
SELECT some_field
FROM some_table
WHERE some_other_field=some_value(+);
I simplified and annonimized the code, but im curious whats the (+) at the end. I don't remember seeing that in mssql world ever.
It's Oracle old outer join syntax:
To write a query that performs an outer join of tables A and B and
returns all rows from A (a left outer join), use the LEFT [OUTER] JOIN
syntax in the FROM clause, or apply the outer join operator (+) to all
columns of B in the join condition in the WHERE clause. For all rows
in A that have no matching rows in B, Oracle Database returns null for
any select list expressions containing columns of B.
http://docs.oracle.com/cd/B19306_01/server.102/b14200/queries006.htm
Related
This question already has answers here:
Oracle: What does `(+)` do in a WHERE clause?
(4 answers)
Closed 5 years ago.
Recently I observed the following syntax:
AND TRUNC (SYSDATE) + 1 BETWEEN a(+) AND b(+)
I know that the (+) sign is used to address left or right join in conditions like:
and a = b(+)
... but I have no idea what it means in the BETWEEN function.
Can someone explain, please, or better give an example using BETWEEN function?
Thank you,
The Oracle docs says:
Oracle recommends that you use the FROM clause OUTER JOIN syntax
rather than the Oracle join operator. Outer join queries that use the
Oracle join operator (+) are subject to the following rules and
restrictions, which do not apply to the FROM clause OUTER JOIN syntax:
This question already has answers here:
Oracle "(+)" Operator
(4 answers)
Closed 6 years ago.
Suppose there is one condition,
(+) =
i know (+) used in join of column but what does it mean in this condition
The Oracle (+)= syntax is the equivalent for OUTER JOINS.
a.column (+)= b.column
means "retrieve the record from b even if there is no match with a" (RIGH OUTER JOIN)
a.column = b.column (+)
means "retrieve the record from a even if there is no match with b" (LEFT OUTER JOIN)
This question already has answers here:
What is the difference between "INNER JOIN" and "OUTER JOIN"?
(28 answers)
Closed 8 years ago.
I have about 6 months novice experience in SQL, TSQL, SSIS, ETL. As I find myself using JOIN statements more and more in my intern project I have been experimenting with the different JOIN statements. I wanted to confirm my findings. Are the following statements accurate pertaining to the conclusion of JOIN statements in SQL Server?:
1)I did a LEFT OUTER JOIN query and did the same query using JOIN which yielded the same results; are all JOIN statements LEFT OUTER associated in SQL Server?
2)I did a LEFT OUTER JOIN WHERE 2nd table PK (joined to) IS NOT NULL and did the same query using an INNER JOIN which yielded the same results; is it safe to say the the INNER JOIN statement will yield only matched records? and is the same as LEFT OUTER JOIN where joined records IS NOT NULL ?
The reason I'm asking is because I have been only using LEFT OUTER JOINS because that is what I was comfortable with. However, I want to eliminate as much code as possible when writing queries to be more efficient. I just wanted to make sure my observations are correct.
Also, are there any tips that you could provide on easily figuring out which JOIN statement is appropriate for specific queries? For instance, what JOIN would you use if you wanted to yield non-matching records?
Thanks.
A join or inner join (same thing) between table A and table B on, for instance, field1, would narrow in on all rows of table A and B sharing the same field1 value.
A left outer join between A and B, on field1, would show all rows of table A, and only those rows of table B that have a field1 existing in table A.
Where the rows of field1 on table A have a field1 value that doesn't exist in table B, the table B value would show null for field1, but the row of table A would be retained because it is an outer join. These are rows that wouldn't show up in a join which is an implied inner join.
If you get the same results doing a join between table A and table B as you do a left outer join between table A and B, then whatever fields you're joining on have values that exist in both tables. No value for any of the joined fields in A or B exist exclusively in A or B, they all exist in both A and B.
It is also possible you're putting criteria into the where clause that belongs in the on clause of the outer join, which may be causing your confusion. In my example above of tables A and B, where A is being left outer joined with B, you would put any criteria related to table B in the on clause, not the where clause, otherwise you would essentially be turning the outer join into an inner join. For example if you had b.field4 = 12 in the WHERE clause, and table B didn't have a match with A, it would be null and that criteria would fail, and it'd no longer come back even though you used a left outer join. That may be what you are referring to.
JOIN's are mapped to 'INNER JOIN' by default
This question already has answers here:
Oracle "(+)" Operator
(4 answers)
Closed 9 years ago.
The query is as follows
select tbl1.x, tbl2.y
from
tbl1, tbl2
where tbl1.some_column (+) = tbl2.some_column
AND tbl1.some_column2 (+) = 'Y'
What confuses me is this part
AND tbl1.some_column2 (+) = 'Y'
What does it mean?? If I remove the (+) the query returns completely different number of rows. I do understand the application of (+) when there are columns names on the both sides of the =, but what does (+) do when there is a string on the one side of the = ?
It's legacy syntax that Oracle had before they had LEFT OUTER JOIN (or, in this case, probably RIGHT OUTER JOIN).
No need to use it anymore in modern Oracle (at least from 9i, maybe even 8i).
Now you can use the standard SQL join syntax:
SELECT tbl1.x, tbl2.y
FROM tbl1 RIGHT OUTER JOIN tbl2
ON ( tbl1.some_column = tbl2.some_column AND tbl1.some_column2 = 'Y')
This question already has answers here:
Explicit vs implicit SQL joins
(12 answers)
Condition within JOIN or WHERE
(10 answers)
Closed 9 years ago.
I know, if you want the inner join of two tables, you can write SQL in the following syntax.
select tableA.columnA
from tableA
inner join tableB on tableA.columnB=tableB.columnB
Alternatively, you can write the following.
select tableA.columnA
from tableA,
tableB
where tableA.columnB=tableB.columnB
so, which is better in terms of performance?
There is no difference in terms of performance. The where clause is in fact the same as INNER JOIN when it comes to relational algabra.
Read here for a brief explaination
Make sure you understand how inner joins work though, inner join will return more records than you might expect if one of your tables contain duplicate records. So basically, for each record in table A, it will return all the matching records in table B, and if the next record in table A matches the same records in table B, they will appear again. Read more here.