Solved

DB2 -- COMPLEX SQL JOIN

Posted on 2001-08-31
6
2,661 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

Independent Software Vendors: 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!

Question has a verified solution.

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

Suggested Solutions

Entity Framework is a powerful tool to help you interact with the DataBase but still doesn't help much when we have a Stored Procedure that returns more than one resultset. The solution takes some of out-of-the-box thinking; read on!
As technology users and professionals, we’re always learning. Our universal interest in advancing our knowledge of the trade is unmatched by most industries. It’s a curiosity that makes sense, given the climate of change. Within that, there lies a…
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…
Polish reports in Access so they look terrific. Take yourself to another level. Equations, Back Color, Alternate Back Color. Write easy VBA Code. Tighten space to use less pages. Launch report from a menu, considering criteria only when it is filled…

749 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