473,396 Members | 2,098 Online
Bytes | Software Development & Data Engineering Community
Post Job

Home Posts Topics Members FAQ

Join Bytes to post your question to a community of 473,396 software developers and data experts.

SQL 9i OUTER JOIN QUERY

hi friends,
i have one query related to oracle9i outer join condition

it is mentioned that we can't use (+) with the operand of OR
and IN operators

example

select e.last_name,e.department_id,d.department_name,d.de partment_id
from employees e , departments d
where e.department_id(+) = d.department_id
or d.department_id = 100

this gives error =>

where e.department_id(+) = d.department_id
*
ERROR at line 3:
ORA-01719: outer join operator (+) not allowed in operand of OR or IN
*************************************************
but this query works fine with the IN operator, i couldn't find the
reson how the following query works perfectly with IN and (+)
operator.
select e.last_name,e.department_id,d.department_name,d.de partment_id
from employees e , departments d
where e.department_id(+) in ( d.department_id)
so friends please help to find reason for this.
Jul 19 '05 #1
1 16994

Hi, Rahul. What are you trying to do? Saying 'WHERE E.DEPARTMENT_ID IN
(D.DEPARTMENT_ID)' doesn't even look like legal SQL to me. And I can't
imagine what '(+)' could mean in that construct. What happened to the
DEPARTMENT_ID = 100 in the example using IN? Since you are joining over
DEPARTMENT_ID, you are going to get all of them anyway.

As a beginning, you should restructure your syntax to eliminate the archaic
outer join syntax in favor of the proper syntax. Joins do not belong in the
WHERE clause. There is never a time when the long-deprecated '(+)' operator
should be used.

SELECT
E.LAST_NAME,
D.DEPARMENT_NAME,
D.DEPARTMENT_ID

FROM EMPLOYEES E LEFT OUTER JOIN DEPARTMENTS D
ON E.DEPARTMENT_ID = D.DEPARTMENT_ID;

Apologies, but I can't understand how the 'DEPARTMENT_ID = 100' fits into
this. The above query will already return department 100 data as long as
there is any employee in that department. If you want the department 100
data even in the case that no one is in that department, you should add a
UNION to that effect:

SELECT
E.LAST_NAME,
D.DEPARMENT_NAME,
D.DEPARTMENT_ID

FROM EMPLOYEES E LEFT OUTER JOIN DEPARTMENTS D
ON E.DEPARTMENT_ID = D.DEPARTMENT_ID

UNION

SELECT
E.LAST_NAME,
D.DEPARMENT_NAME,
D.DEPARTMENT_ID

FROM EMPLOYEES E RIGHT OUTER JOIN DEPARTMENTS D
ON E.DEPARTMENT_ID = D.DEPARTMENT_ID

WHERE D.DEPARTMENT_ID = 100;

If I haven't understood you and you still need more help, could you just
state in English what you'd like to get back from the server, rather than
posting your code, and I'll try to give you a query to get what you're
looking for?

I hope this was helpful, but I'm not certain enough that I understand what
you're trying to do.

Brian
Jul 19 '05 #2

This thread has been closed and replies have been disabled. Please start a new discussion.

Similar topics

1
by: Dave | last post by:
Hi I have the following 4 tables and I need to do a fully outerjoin on them. create table A (a number, b number, c char(10), primary key (a,b)) create table B (a number, b number, c ...
1
by: Steve | last post by:
I have a SQL query I'm invoking via VB6 & ADO 2.8, that requires three "Left Outer Joins" in order to return every transaction for a specific set of criteria. Using three "Left Outer Joins"...
7
by: Steve | last post by:
I have a SQL query I'm invoking via VB6 & ADO 2.8, that requires three "Left Outer Joins" in order to return every transaction for a specific set of criteria. Using three "Left Outer Joins"...
3
by: Martin | last post by:
Hello everybody, I have the following question. As a join clause on Oracle we use " table1.field1 = table2.field1 (+) " On SQL Server we use " table1.field1 *= table2.field1 " Does DB2...
4
by: Anthony Robinson | last post by:
I was actually just wondering if someone could possibly take a look and tell me what I may be doing wrong in this query? I keep getting ambiguous column errors and have no idea why...? Thanks in...
3
by: Ian Boyd | last post by:
i know nothing about DB2, but i'm sure this must be possible. i'm trying to get a client to create a view (which it turns out is called a "Logical" in DB2). The query needs a LEFT OUTER JOIN, but...
3
by: deko | last post by:
From what I understand, an Inner Join narrow the rows selected to the table with the least results... and an Outer Join does the opposite... SELECT qryTxToQ1.Q1Total, qryTxToQ2.Q2Total,...
3
by: Doug | last post by:
Hi, I'm more familiar with MSSQL than Access syntax and have run into a problem with correctly putting ( )'s around the joins in a 3 table query. I want to INNER JOIN lenders and accounts and...
4
by: Brian Parker | last post by:
I'm new to ms-sqlserver ( 2000 ) and need to get an OUTER JOIN working on a three table query. Assumptions: -- I have events in the Event table. -- Each event CAN have one Transaction, but it's...
3
by: nico3334 | last post by:
I currently have a query that Joins 2 Tables (Table1 and Table2) using LEFT OUTER JOIN. Here is an example of that query: SELECT a.supply, a.state, b.cost FROM Table1 a LEFT...
0
by: Charles Arthur | last post by:
How do i turn on java script on a villaon, callus and itel keypad mobile phone
0
BarryA
by: BarryA | last post by:
What are the essential steps and strategies outlined in the Data Structures and Algorithms (DSA) roadmap for aspiring data scientists? How can individuals effectively utilize this roadmap to progress...
1
by: nemocccc | last post by:
hello, everyone, I want to develop a software for my android phone for daily needs, any suggestions?
0
by: Hystou | last post by:
There are some requirements for setting up RAID: 1. The motherboard and BIOS support RAID configuration. 2. The motherboard has 2 or more available SATA protocol SSD/HDD slots (including MSATA, M.2...
0
by: Hystou | last post by:
Most computers default to English, but sometimes we require a different language, especially when relocating. Forgot to request a specific language before your computer shipped? No problem! You can...
0
Oralloy
by: Oralloy | last post by:
Hello folks, I am unable to find appropriate documentation on the type promotion of bit-fields when using the generalised comparison operator "<=>". The problem is that using the GNU compilers,...
0
by: Hystou | last post by:
Overview: Windows 11 and 10 have less user interface control over operating system update behaviour than previous versions of Windows. In Windows 11 and 10, there is no way to turn off the Windows...
0
tracyyun
by: tracyyun | last post by:
Dear forum friends, With the development of smart home technology, a variety of wireless communication protocols have appeared on the market, such as Zigbee, Z-Wave, Wi-Fi, Bluetooth, etc. Each...
0
agi2029
by: agi2029 | last post by:
Let's talk about the concept of autonomous AI software engineers and no-code agents. These AIs are designed to manage the entire lifecycle of a software development project—planning, coding, testing,...

By using Bytes.com and it's services, you agree to our Privacy Policy and Terms of Use.

To disable or enable advertisements and analytics tracking please visit the manage ads & tracking page.