Want to win a PS4? Go Premium and enter to win our High-Tech Treats giveaway. Enter to Win

x
?
Solved

DB2 -- COMPLEX SQL JOIN

Posted on 2001-08-31
6
Medium Priority
?
2,702 Views
Last Modified: 2008-02-01
I have some SQL which does not perform on DB2.  It was originally a couple of queries joined together in Access. I pulled the queries appart and create this join.  When issued from the command center it does not error but it does not ever return.  Is there a fundamental mistake in this query?  Is there an optimal way to approach this type of join?  Here is the sql.  

Thanks,

Jeff

SELECT OPT1.OTY_DESCRIPTION,
       OPT1.ODF_SPEC_NO,
       OPT1.OPT_SPEC_SIGN,
       OPT1.OPT_DESCRIPTION,
       OPT2.ID,
       OPT2.OPT_SPEC_SIGN,
       OPT2.OPT_DESCRIPTION,
       OPT2.ODF_SPEC_NO
       FROM (SELECT DISTINCT
                    OTY_DESCRIPTION,
                    ODF_SPEC_NO,
                    OPT_SPEC_SIGN,
                    OPT_DESCRIPTION
               FROM EPOPTTYP_TBL INNER JOIN (EPOPTION_TBL INNER JOIN EPOPTDEF_TBL ON EPOPTION_TBL.ID = ODF_TO_OPT_RT) ON EPOPTTYP_TBL.ID = OPT_TO_OTY_RT
              WHERE OPT_TO_MDL_RT = 4
                AND ODF_SP_CODE = 'S'
                AND ODF_MONTH_FROM <= 200012
                AND ODF_MONTH_TO >= 200012
                AND OPT_MONTH_FROM <= 200012
                AND OPT_MONTH_TO >=200012) OPT1
       INNER JOIN (SELECT DISTINCT
                          EPOPTION_TBL.ID,
                          OPT_SPEC_SIGN,
                          OPT_DESCRIPTION,
                          ODF_SPEC_NO
                     FROM EPOPTION_TBL INNER JOIN EPOPTDEF_TBL ON EPOPTION_TBL.ID = ODF_TO_OPT_RT
                    WHERE OPT_TO_MDL_RT = 4
                      AND ODF_SP_CODE = 'P'
                      AND ODF_MONTH_FROM <= 200012
                      AND ODF_MONTH_TO >=200012
                      AND OPT_MONTH_FROM <= 200012
                      AND OPT_MONTH_TO >= 200012) OPT2
       ON OPT1.ODF_SPEC_NO = OPT2.ODF_SPEC_NO
0
Comment
Question by:jwstairs
[X]
Welcome to Experts Exchange

Add your voice to the tech community where 5M+ people just like you are talking about what matters.

  • Help others & share knowledge
  • Earn cash & points
  • Learn & ask questions
6 Comments
 
LVL 5

Expert Comment

by:kelfink
ID: 6446325
Certainly is complex.

Um, is this the whole thing?  Looks like it's not all there.  If I'm counting correctly, you've not closed the nested query in the top-level FROM clause...

Also, if you could post sample definitions of the tables involved, that would help us to try running the query.

Kevin
0
 
LVL 3

Expert Comment

by:ibro
ID: 6450346
what is the datatype of OPT_MONTH_FROM and OPT_MONTH_FROM. Is it numeric or date? Maybe you have problem with the where clause.
 The statement seems ok to me.
0
 

Expert Comment

by:gregnash
ID: 6454990
Hi,
I would also ask:
- How many rows in each of the tables?
- What size is your bufferpool?
- Is the CPU being utilized at 100%, or is the disc thrashing, or neither, or both?  (The ways to find out differ depending on your platform, which you haven't named).
- What indexes do you have on the tables?

If you can answer those, I'll have a go at why your query is slow.

-Greg
0
Technology Partners: We Want Your Opinion!

We value your feedback.

Take our survey and automatically be enter to win anyone of the following:
Yeti Cooler, Amazon eGift Card, and Movie eGift Card!

 

Author Comment

by:jwstairs
ID: 6469963
The problem has been temporarily fixed.  It is no longer a requirement.  Thanks for having a look anyway.

Jeff
0
 
LVL 54

Expert Comment

by:nico5038
ID: 7261912

No comment has been added lately, so it's time to clean up this TA.
I will leave a recommendation in the Cleanup topic area that this question is:
 - PAQ'd and pts refunded
Please leave any comments here within the
next seven days.

PLEASE DO NOT ACCEPT THIS COMMENT AS AN ANSWER !

Nic;o)
0
 

Accepted Solution

by:
Jgould earned 0 total points
ID: 7291837
Question has been closed as per recommendation

JGould-EE Moderator
0

Featured Post

Get your Conversational Ransomware Defense e‑book

This e-book gives you an insight into the ransomware threat and reviews the fundamentals of top-notch ransomware preparedness and recovery. To help you protect yourself and your organization. The initial infection may be inevitable, so the best protection is to be fully prepared.

Question has a verified solution.

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

Recently, Microsoft released a best-practice guide for securing Active Directory. It's a whopping 300+ pages long. Those of us tasked with securing our company’s databases and systems would, ideally, have time to devote to learning the ins and outs…
A Stored Procedure in Microsoft SQL Server is a powerful feature that it can be used to execute the Data Manipulation Language (DML) or Data Definition Language (DDL). Depending on business requirements, a single Stored Procedure can return differe…
Video by: Steve
Using examples as well as descriptions, step through each of the common simple join types, explaining differences in syntax, differences in expected outputs and showing how the queries run along with the actual outputs based upon a simple set of dem…
In this video, Percona Solutions Engineer Barrett Chambers discusses some of the basic syntax differences between MySQL and MongoDB. To learn more check out our webinar on MongoDB administration for MySQL DBA: https://www.percona.com/resources/we…
Suggested Courses

604 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