Solved

DB2 -- COMPLEX SQL JOIN

Posted on 2001-08-31
6
2,629 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
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
Netscaler Common Configuration How To guides

If you use NetScaler you will want to see these guides. The NetScaler How To Guides show administrators how to get NetScaler up and configured by providing instructions for common scenarios and some not so common ones.

 

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

Netscaler Common Configuration How To guides

If you use NetScaler you will want to see these guides. The NetScaler How To Guides show administrators how to get NetScaler up and configured by providing instructions for common scenarios and some not so common ones.

Question has a verified solution.

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

I guess that all of us know that caching the data usually increase the performance, but I worried if all of us are aware about the risk that caching the data provides and how to minimize this.  That’s the reason why I decided to write this short art…
These days, all we hear about hacktivists took down so and so websites and retrieved thousands of user’s data. One of the techniques to get unauthorized access to database is by performing SQL injection. This article is quite lengthy which gives bas…
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…

920 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

15 Experts available now in Live!

Get 1:1 Help Now