Thanks catchmeifuwant,
But , this is still not correct, for one, the (+) operator does not seem to work for OUTER JOINS in 9i.
Main Topics
Browse All TopicsHello all,
Here is the original SQL statement that did not need OUTER JOIN functionality, very basic all INNER:
SELECT DISTINCT
a.group_id,
a.workorder_no,
b.assignment_no,
d.document_no,
d.source,
b.assignment_type,
b.assignment_class,
b.setid,
b.service_cust_id,
b.service_addr_num,
d.image_file_name,
b.start_dt,
b.end_dt,
d.week_end_dt,
b.business_type
FROM sysadm.ps_pb_wkord a,
sysadm.ps_pb_wkord_assig b,
sysadm.ps_pb_ts_control c,
sysadm.ps_pb_ts_header d
WHERE a.group_id = b.group_id
AND a.workorder_no = b.workorder_no
AND a.group_id = c.group_id
AND b.assignment_no = c.assignment_no
AND c.group_id = d.group_id
AND c.control_no = d.control_no
However, now the business rules need an outer join on the join of 'b.assignment_no = c.assignment_no' to retrieve assignments
that are in b but no match in c. OUTER JOIN, right?. Seperate queries against the tables prove that there are quite a few records in table b that are not in table c. Here is the new query with the OUTER JOIN that I thought would remedy this:
SELECT DISTINCT
a.group_id,
a.workorder_no,
b.assignment_no,
d.document_no,
d.source,
b.assignment_type,
b.assignment_class,
b.setid,
b.service_cust_id,
b.service_addr_num,
d.image_file_name,
b.start_dt,
b.end_dt,
d.week_end_dt,
b.business_type
FROM sysadm.ps_pb_wkord_assig b
LEFT OUTER JOIN
sysadm.ps_pb_ts_control c
ON
b.assignment_no = c.assignment_no,
sysadm.ps_pb_wkord a,
sysadm.ps_pb_ts_header d
WHERE a.group_id = b.group_id
AND a.workorder_no = b.workorder_no
AND a.group_id = c.group_id
AND c.group_id = d.group_id
AND c.control_no = d.control_no
This query however produces the exact same results as the query without the OUTER JOIN. Is the problem that the other tables involved that do not have to be OUTER JOINED need to use the new 9i INNER JOIN syntax? Basically, how do you OUTER JOIN some tables while INNER JOINING the others. Thanks.
This Question has been solved and asker verified All Experts Exchange premium technology solutions are available to subscription members.
Experts Exchange has been collecting answers to technology questions since 1996…3 million and counting! If you have a question, chances are we already have your answer.
If you can't find the exact answer you're looking for, ask our exclusive community of 50,000 experts. You’ll get a personalized answer from a trusted professional.
Thousands of free tech tips, tricks, how-to’s and tutorials are available in our peer reviewed articles section. See for yourself how smart our experts are, no login required.
Access the answers to your technology questions today.
30-day free trial. Register in 60 seconds.
Members of the expert community talk about why the experience at Experts Exchange is different than what you will find anywhere else.

Try it out and discover for yourself.
30-day free trial. Register in 60 seconds.
Join the community of experts here and help other tech pros by answering question in your area of expertise. You can earn FREE access to all Experts Exchange's premium features and resources.
I have tried all the possible simple solutions like your suggestion using the (+) operator. I read
somewhere that Oracle 9i does not accept the (+) anymore. The only syntax
that returns results is using the LEFT OUTER JOIN syntax. This syntax produces the desired results when run
against just the 2 tables:
Select distinct a.assignment_no,b.assignme
ps_pb_ts_control b ON a.assignment_no = b.assignment_no
You get all from a that match b, plus those assignments in a that don't match b. Exactly what I want.
I think the problem is that when I add in the other tables, that don't need to be outer joined, and if I don't
use the same syntax, like saying c INNER JOIN d ON c.group_id = d.group_id, for a regular join; the
syntax is off and the outer join is not used.
I think the main question is what syntax is necessary to do some tables OUTER JOIN, and some INNER.
BTW, I think it would be overkill to send the tables and sample data, It's more a theory question. Thanks.
You can still use the (+) in 9i
Your problem comes from the fact that you must apply the outer join operator (+) to all columns of C table in the where clause
Try
WHERE a.group_id = b.group_id
AND a.workorder_no = b.workorder_no
AND a.group_id = c.group_id(+)
AND b.assignment_no = c.assignment_no(+)
AND d.group_id = c.group_id(+)
AND d.control_no = c.control_no(+)
FROM sysadm.ps_pb_wkord_assig b
LEFT OUTER JOIN
(SELECT -- c and d columns --
FROM
sysadm.ps_pb_ts_control c
INNER JOIN sysadm.ps_pb_ts_header d ON
c.group_id = d.group_id
AND c.control_no = d.control_no
INNER JOIN sysadm.ps_pb_wkord a ON
a.group_id = b.group_id) cc
ON
b.assignment_no = cc.assignment_no
AND cc.group_id = b.group_id
AND cc.workorder_no = b.workorder_no
Business Accounts
Answer for Membership
by: catchmeifuwantPosted on 2003-09-17 at 09:18:47ID: 9379316
This is the query you are probably after...
b.assignme nt_no,d.do cument_no, d.source,b .assignmen t_type,b.a ssignment_ class, b.service_ addr_num,d .image_fil e_name,b.s tart_dt,b. end_dt,d.w eek_end_dt ,b.busines s_type
com/docs/c d/B10501_0 1/server.9 20/ a96540/ queries7.h tm#2054014
SELECT DISTINCT a.group_id,a.workorder_no,
b.setid,b.service_cust_id,
FROM
sysadm.ps_pb_wkord a,
sysadm.ps_pb_wkord_assig b,
sysadm.ps_pb_ts_control c,
sysadm.ps_pb_ts_header d
WHERE a.group_id = b.group_id
AND a.workorder_no = b.workorder_no
AND a.group_id = c.group_id
AND b.assignment_no = c.assignment_no (+)
AND c.group_id = d.group_id
AND c.control_no = d.control_no;
Here are some rule to be followed with Joins:
To write a query that performs an outer join of tables A and B and returns all rows from A (a left outer join),
use the LEFT [OUTER] JOIN syntax in the FROM clause, or apply the outer join operator (+) to all columns of B in the
join condition in the WHERE clause. For all rows in A that have no matching rows in B, Oracle returns null for any
select list expressions containing columns of B.
To write a query that performs an outer join of tables A and B and returns all rows from B (a right outer join),
use the RIGHT [OUTER] JOIN syntax in the FROM clause, or apply the outer join operator (+) to all columns of A in
the join condition in the WHERE clause. For all rows in B that have no matching rows in A, Oracle returns null for
any select list expressions containing columns of A.
To write a query that performs an outer join and returns all rows from A and B,
extended with nulls if they do not satisfy the join condition (a full outer join), use the FULL [OUTER] JOIN
syntax in the FROM clause.
Taken from http://download-uk.oracle.