This question already has answers here:
What does (+) do in Oracle SQL?
(4 answers)
Closed 9 years ago.
I just stumbled across a SQL+-Query which uses (+). I've never worked with SQL+ before and I've never seen something like this. I tried to ask Google about it, but I couldn't find anything useful since Google obviously filters the "(+)" and just ignores it...
Example:
[...]
where [...]
AND 16791688 = T7mm.child_fielddef_id (+)
AND T7mm.parent_dbid = T7.dbid (+)
AND T1.dbid <> 0 [...]
it is an Oracle specific shortcut for OUTER JOIN
It makes the join an outer join rather than an inner join:
SELECT
A.*,
B.*
FROM
A,
B
WHERE
A.ID = B.ID(+)
is equivalent to:
SELECT
A.*,
B.*
FROM
A
LEFT JOIN B ON A.ID = B.ID
The (+) notation is the old Oracle syntax for SQL queries. Now it is generally viewed as best practice to use the ANSI standard with the LEFT JOIN keywords instead
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:
When or why would you use a right outer join instead of left?
(11 answers)
Closed 6 years ago.
If we can interchange left or right join then what is the use of any specific type of join??
I think this is actually a good question. I have never heard a really good reason why right join exists. Maybe something from the very old days of SQL required it? It would be really cool is someone had an answer other than appearance.
I like the comment by Gordon.
1 - 1 is the same as 1 + (-1)
To expand on the idea, I have always felt it was for looks. I always use left joins and order the tables in my query to achieve the results I want but could easily use right joins or a mix.
For example
Select a.field, b.field
From a
left join b on a.id = b.aid
will return the same results as:
Select a.field, b.field
From b
right join a on a.id = b.aid
What it comes down to is that the first table is the left table and the next table is the right table. If you want all the records from a it has to be first in a left join and has to be second in a right join.
This question already has answers here:
Inner join vs Where
(19 answers)
Closed 6 years ago.
Whats the difference between Query A and Query B. Both table_a and table_b are having 700k+ records. The obvious difference I can see is the speed (performance). Additionally, our Oracle consultants tend to write sql script using Query B.
Query A
select *
from table_a a
inner join table_b b
on a.id = b.id
Query B
select *
from table_a a,table_b b
where a.id = b.id
The second query is using more of a relational model(it is not recommended anymore.) concept whereas the first one is ANSI compliant and more readable.
Although this article is in SQL Server by Aaron but it gives a useful insight about the old practice: Bad habits to kick : using old-style JOINs
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
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')