Home » RDBMS Server » Server Administration » Can we avoid using the (+) keyword in a outer join
Can we avoid using the (+) keyword in a outer join [message #374239] Fri, 01 June 2001 00:31 Go to next message
Sreenivas
Messages: 15
Registered: January 2000
Junior Member
Hi ,
Can we write an outer join in oracle without using the
(+) keyword?. The idea is the same query should be used in informix (which has a different syntax for a outer query ,,.i.e we have to use OUTER instead of (+)).
The outer join query should be database independent(between oracle and infomix).
Re: Can we avoid using the (+) keyword in a outer join [message #374240 is a reply to message #374239] Fri, 01 June 2001 01:08 Go to previous messageGo to next message
Rakesh Goel
Messages: 8
Registered: May 2001
Junior Member
use the query without outer join, add a union query for non matching records with the main query. It will solve your problem.
Re: Can we avoid using the (+) keyword in a outer join [message #374241 is a reply to message #374239] Fri, 01 June 2001 01:08 Go to previous messageGo to next message
Rakesh Goel
Messages: 8
Registered: May 2001
Junior Member
use the query without outer join, add a union query for non matching records with the main query. It will solve your problem.
Re: Can we avoid using the (+) keyword in a outer join [message #374243 is a reply to message #374241] Fri, 01 June 2001 04:10 Go to previous messageGo to next message
Srinivas
Messages: 138
Registered: June 2000
Senior Member
Can u give an example query please?
Re: Can we avoid using the (+) keyword in a outer join [message #374247 is a reply to message #374243] Fri, 01 June 2001 16:17 Go to previous message
Andrew again...
Messages: 270
Registered: July 2000
Senior Member
This is untested, so you might have to play with it a bit. Assume you have DEPTs which may have no EMPs.

The Oracle way:
select d.dept_name, e.emp_name
from dept d, emp e
where d.dept# = e.dept# (+);

The workaround:
select d.dept_name, e.emp_name
from dept d, emp e
where d.dept# = e.dept#
UNION
select d.dept_name, null
from dept d
where d.dept# not in (select e.dept# from emp e);

To make it more efficient - eliminate the "not in":
select d.dept_name, e.emp_name
from dept d, emp e
where d.dept# = e.dept#
UNION
select d.dept_name, null
from dept d
where d.dept# in
(select e.dept# from emp e
MINUS
select d1.dept# from dept d1);

Footnote - Note that UNION and UNION ALL are similar. UNION eliminates duplicates from the resultset (something like DISTINCT). UNION ALL does not. UNION ALL is faster because there is one less step.
Previous Topic: test
Next Topic: Finding the Nth highest Salary value of given Employee Table
Goto Forum:
  


Current Time: Mon Dec 23 12:49:20 CST 2024