0

I have the following query

SELECT * 
FROM tableA, tableB
WHERE Conditions [+]

What does this keyword Conditions[+] Stands for? How this query behaves as a outer join?

wali
  • 229
  • 4
  • 8
  • 21
  • 3
    The query you posted doesn't seem to make sense. Given your reference to an "outer join", do you perhaps mean `WHERE tableA.col1 = tableB.col1(+)`? – Justin Cave Aug 17 '12 at 15:41
  • I work on MS-SQL using standard SQL. I never seen such syntax. It is just and example of outer join. I want to know how It can be written in standard sql. – wali Aug 17 '12 at 15:49

4 Answers4

6

That is old Oracle Join syntax.

SELECT * 
FROM tableA, tableB
WHERE Conditions [+] -- this should be tableA (+) = tableB

The positioning of the + sign denotes the JOIN syntax.

If you query was:

SELECT * 
FROM tableA, tableB
WHERE tableA.id (+) = tableB.Id

Then it would be showing a RIGHT OUTER JOIN so the equivalent is:

SELECT * 
FROM tableA
RIGHT OUTER JOIN tableB
   ON tableB.id = tableA.Id

If the + sign was on the other side then it would be a LEFT OUTER JOIN

SELECT * 
FROM tableA, tableB
WHERE tableA.id  = tableB.Id (+)

is equivalent to

SELECT * 
FROM tableA
LEFT OUTER JOIN tableB
   ON tableA.id = tableB.Id

I would advise using standard join syntax though.

If you do not specify a + sign then it will be interpreted as an INNER JOIN

SELECT * 
FROM tableA, tableB
WHERE tableA = tableB

it's equivalent is:

SELECT * 
FROM tableA
INNER JOIN tableB
    ON tableA.id = tableB.id

A FULL OUTER JOIN would be written using two SELECT statements and a UNION:

SELECT * 
FROM tableA, tableB
WHERE tableA.id  = tableB.Id (+)
UNION
SELECT * 
FROM tableA, tableB
WHERE tableA.id (+) = tableB.Id 

It's equivalent is:

SELECT * 
FROM tableA
FULL OUTER JOIN tableB
    ON tableA.id = tableB.id

Here is a tutorial that explains a lot of these:

Old Outer Join Syntax

Taryn
  • 242,637
  • 56
  • 362
  • 405
3

It is not important how that behaves. You should use the standard syntax for outer joins:

select *
from tableA left outer join
     tableB
     on . . .

The "(+)" syntax was introduced by Oracle before the standard syntax, and it is highly out of date.

Gordon Linoff
  • 1,242,037
  • 58
  • 646
  • 786
0

'Conditions' here just means what you're using to filter all this data.

LIke here's an example:

SELECT * 
FROM tableA, tableB
WHERE Name like '%Bob%'

would return names that have "Bob" anywhere inside.

About outer joins, actually you'd use that in the FROM clause:

So maybe

SELECT * 
FROM tableA ta 
     OUTER JOIN tableB tb
     ON ta.name = tb.name
WHERE ta.age <> 10

and there where here is optional, by the way

Caffeinated
  • 11,982
  • 40
  • 122
  • 216
  • 1
    Thanks for the informaion. But I want to know how it will behave like Left outer join, OR Right outer join OR Full outer join? OR – wali Aug 17 '12 at 15:43
0

I hate to just copy & paste an answer, but this sort of thing can be found pretty easily if you do a little searching...

An outer join returns rows for one table, even when there are no matching rows in the other. You specify an outer join in Oracle by placing a plus sign (+) in parentheses following the column names from the optional table in your WHERE clause. For example:

SELECT ut.table_name, uc.constraint_name 
FROM user_tables ut, user_constraints uc 
WHERE ut.table_name = uc.table_name(+);

The (+) after uc.table_name makes the user_constraint table optional. The query returns all tables, and where there are no corresponding constraint records, Oracle supplies a null in the constraint name column.

Jeremy Wiggins
  • 7,239
  • 6
  • 41
  • 56