Solved

DB2 -- COMPLEX SQL JOIN

Posted on 2001-08-31
6
2,616 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
6 Comments
 
LVL 5

Expert Comment

by:kelfink
Comment Utility
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
Comment Utility
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
Comment Utility
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
Microsoft Certification Exam 74-409

Veeam® is happy to provide the Microsoft community with a study guide prepared by MVP and MCT, Orin Thomas. This guide will take you through each of the exam objectives, helping you to prepare for and pass the examination.

 

Author Comment

by:jwstairs
Comment Utility
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
Comment Utility

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
Comment Utility
Question has been closed as per recommendation

JGould-EE Moderator
0

Featured Post

What Should I Do With This Threat Intelligence?

Are you wondering if you actually need threat intelligence? The answer is yes. We explain the basics for creating useful threat intelligence.

Join & Write a Comment

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!
CCModeler offers a way to enter basic information like entities, attributes and relationships and export them as yEd or erviz diagram. It also can import existing Access or SQL Server tables with relationships.
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…

743 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

17 Experts available now in Live!

Get 1:1 Help Now