Solved

Alternative to FULL OUTER JOIN

Posted on 2008-10-24
7
1,273 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
Find Ransomware Secrets With All-Source Analysis

Ransomware has become a major concern for organizations; its prevalence has grown due to past successes achieved by threat actors. While each ransomware variant is different, we’ve seen some common tactics and trends used among the authors of the malware.

 
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

How your wiki can always stay up-to-date

Quip doubles as a “living” wiki and a project management tool that evolves with your organization. As you finish projects in Quip, the work remains, easily accessible to all team members, new and old.
- Increase transparency
- Onboard new hires faster
- Access from mobile/offline

Join & Write a Comment

November 2009 Recently, a question came up in the DB2 forum regarding the date format in DB2 UDB for AS/400.  Apparently in UDB LUW (Linux/Unix/Windows), the date format is a system-wide setting, and is not controlled at the session level.  I'm n…
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…
In this tutorial you'll learn about bandwidth monitoring with flows and packet sniffing with our network monitoring solution PRTG Network Monitor (https://www.paessler.com/prtg). If you're interested in additional methods for monitoring bandwidt…
When you create an app prototype with Adobe XD, you can insert system screens -- sharing or Control Center, for example -- with just a few clicks. This video shows you how. You can take the full course on Experts Exchange at http://bit.ly/XDcourse.

708 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

Need Help in Real-Time?

Connect with top rated Experts

13 Experts available now in Live!

Get 1:1 Help Now