Solved

Alternative to FULL OUTER JOIN

Posted on 2008-10-24
7
1,276 Views
Last Modified: 2012-05-05
1) We have DB2 V5R3 on iseries AS/400.
2) FULL OUTER JOIN is not supported
3) There is a query we have written with repeating WHERE conditions for LEFT OUTER JOIN UNION RIGHT OUTER JOIN.
4) Can we not write in a single query without repeating WHERE conditions?
0
Comment
Question by:k_murli_krishna
7 Comments
 
LVL 142

Accepted Solution

by:
Guy Hengel [angelIII / a3] earned 25 total points
ID: 22802217
4) no.
0
 
LVL 16

Expert Comment

by:theo kouwenhoven
ID: 22803500
Maybe there is a workarond, please post hte whole SQL query here
0
 
LVL 17

Author Comment

by:k_murli_krishna
ID: 22806981
SELECT e.EMPNO, e.ENAME, d.DEPTNO, d.DEPTNAME FROM EMP e LEFTOUTER JOIN DEPT d ON e.DEPTNO = d.DEPTNO WHERE e.ENAME = 'SCOTT' AND d.DEPTNAME = 'MECH' ORDER BY e.EMPNO
UNION
SELECT e.EMPNO, e.ENAME, d.DEPTNO, d.DEPTNAME FROM EMP e RIGHT OUTER JOIN DEPT d ON e.DEPTNO = d.DEPTNO WHERE e.ENAME = 'SCOTT' AND d.DEPTNAME = 'MECH' ORDER BY e.EMPNO;

Also:
SELECT e.EMPNO, e.ENAME, d.DEPTNO, d.DEPTNAME FROM EMP e LEFTOUTER JOIN DEPT d ON e.DEPTNO = d.DEPTNO WHERE e.ENAME = 'SCOTT' AND d.DEPTNAME = 'MECH' ORDER BY e.EMPNO
UNION
SELECT e.EMPNO, e.ENAME, d.DEPTNO, d.DEPTNAME FROM EMP e RIGHT OUTER JOIN DEPT d ON e.DEPTNO = d.DEPTNO WHERE e.ENAME = 'BRENT' AND d.DEPTNAME = 'ELEC' AND e.SAL > 8000 ORDER BY d.DEPTNO;

Maybe IN and NOT IN can be made use of. For multiple columns IN and NOT IN which was also not supported, joins were used as an alternative.
0
Master Your Team's Linux and Cloud Stack

Come see why top tech companies like Mailchimp and Media Temple use Linux Academy to build their employee training programs.

 
LVL 37

Assisted Solution

by:momi_sabag
momi_sabag earned 25 total points
ID: 22807588
you could try to have a join with no join conditions (carthesian join) but your solution would probably run faster
0
 
LVL 17

Author Comment

by:k_murli_krishna
ID: 22808118
But, momi, the results would be bloated and not what they should be. Suggest a correct solution else no idea/next to impossible/not possible like angelIIl from one of you is also good enough.
0
 
LVL 16

Assisted Solution

by:theo kouwenhoven
theo kouwenhoven earned 25 total points
ID: 22808945
Did you tried what the performance is/was with a "not in (select....)" ?
0
 
LVL 17

Author Comment

by:k_murli_krishna
ID: 22809647
Thanks, I will try now.
0

Featured Post

Courses: Start Training Online With Pros, Today

Brush up on the basics or master the advanced techniques required to earn essential industry certifications, with Courses. Enroll in a course and start learning today. Training topics range from Android App Dev to the Xen Virtualization Platform.

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

Suggested Solutions

Title # Comments Views Activity
OPENQUERY syntax errors (not recognizing CROSS APPLY) 17 600
SQL400 max size 5 92
filter big file based upon on multipe criteria 2 56
iSeries DB2 SQL - Request user input 12 48
Recursive SQL in UDB/LUW (you can use 'recursive' and 'SQL' in the same sentence) A growing number of database queries lend themselves to recursive solutions.  It's not always easy to spot when recursion is called for, especially for people una…
Recursive SQL in UDB/LUW (it really isn't that hard to do) Recursive SQL is most often used to convert columns to rows or rows to columns.  A previous article described the process of converting rows to columns.  This article will build off of th…
Two types of users will appreciate AOMEI Backupper Pro: 1 - Those with PCIe drives (and haven't found cloning software that works on them). 2 - Those who want a fast clone of their boot drive (no re-boots needed) and it can clone your drive wh…
Established in 1997, Technology Architects has become one of the most reputable technology solutions companies in the country. TA have been providing businesses with cost effective state-of-the-art solutions and unparalleled service that is designed…

776 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question