Thursday, April 4, 2013

Outer Join - Oracle and ANSI SQL Syntax Answer

This  refers to the previous blog here.
The Standard Oracle syntax is pretty straightforward.

SELECT fooa.foo1,
  fooa.foo2,
  foob.foo2
FROM foo fooa,
  foo foob
WHERE fooa.foo1 =foob.foo1(+)
AND fooa.foo3   ='Coming'
AND foob.foo3(+)='Going'


The ANSI SQL syntax is a little trickier.

SELECT fooa.foo1,
fooa.foo2,
foob.foo2
FROM foo fooa
LEFT OUTER JOIN foo foob
ON (fooa.foo1 =foob.foo1
AND foob.foo3 ='Going')
WHERE fooa.foo3='Coming'

There you go for outer joins.

This should be a very good interview question.
 

No comments:

Post a Comment