Link to home
Start Free TrialLog in
Avatar of ChiBella
ChiBella

asked on

Oracle Left Outer Join Problem

Hello,
Can an Oracle pl/sql expert help me construct a left outer join in Oracle 9i that excludes some values in the join table?
Example:

Select a.emp, b.manager from emp a, manager b
where a.empid = b.empid(+)
and b.managerID <> '123';

How do I retrieve all employee info and all manager info except for managerid '123' in one query. The query above cancels out the outer join and limits the results to only the manager table.

Avatar of Guy Hengel [angelIII / a3]
Guy Hengel [angelIII / a3]
Flag of Luxembourg image

this should work better:
Select a.emp, b.manager
from emp a, manager b
where a.empid = b.empid(+)
and b.managerID <> '123' (+)

note the better syntax using LEFT JOIN:

Select a.emp, b.manager
from emp a
left join manager b
 on a.empid = b.empid
 and b.managerID <> '123';

Avatar of ChiBella
ChiBella

ASKER

Select a.emp, b.manager
from emp a, manager b
where a.empid = b.empid(+)
and b.managerID <> '123' (+)

generates an error...SQL command not properly ended.
sorry, but I don't see anything wrong...
note that the LEFT JOIN syntax is preferred, and is eventually to give better results.
The syntax is invalid. Cannot outer on a literal in Oracle. But your preferred sytax does seem to work, however I'm getting the wrong counts back.
ASKER CERTIFIED SOLUTION
Avatar of Guy Hengel [angelIII / a3]
Guy Hengel [angelIII / a3]
Flag of Luxembourg image

Link to home
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
Start Free Trial
thanks...that works!