Advertisement

06.19.2007 at 06:20PM PDT, ID: 22644899
[x]
Attachment Details
[x]
The Solution Rating System

With so many solutions, how can you tell which solutions are most likely to help you and which ones are not? To provide you with a tool to use, we rate our solutions based on various elements that most accurately determine if a solution is a quality solution. To explain what factors affect the solution rating, here are the elements we take into consideration when formulating our solution rating.

  • The Grade of the Solution
  • The Zone Rank of the Expert Providing the Solution
  • The Number of Author and Expert Comments
  • The Number of Experts Contributing
  • The Feedback of the Community

Your Input Matters
Because of the way the system is set up, the most important variable in this equation is you. As a member of Experts Exchange, you are able to cast your vote on the quality of the solutions in regard to how complete, accurate, helpful and easy to understand each solution is. When you provide your feedback, each rating is adjusted accordingly. So, if you see a solution that has a poor rating that you think is a good solution, let us know by rating it. As you do, the rating will be adjusted and will become more accurate for other members of our site.

If you have any suggestions that you would like to make for our rating system, please ask a question in the Suggestions Zone of Community Support.

Thank you!

8.8

Nested Select statements with poor performance

Asked by mpdillon in MS SQL Server

Tags: , ,

I am experiencing extremely poor performace from the Select statement below:

Select sum(Amount) as Amt From TableA
where IDno in (Select BaseIDNo From TableB
                        where Zip in (Select ZIp From TableC
                                             where SlsPsnNo = '501' Group By Zip)
                        Group By BaseIDNo)  

TableA = 16 records
TableB = 35469 records
TableC = 26334 records

This query returns one record in 5 munutes.
If I break out the inner selects:

(Select BaseIDNo From TableB
                          where Zip in (Select ZIp From TableC
                                                where SlsPsnNo = '501' Group By Zip)
                          Group By BaseIDNo)  
This returns a result in less than 1 second. It returns a single record whos value is 29.

Therefore, the full query could be reduced to something like:

Select sum(Amount) as Amt From TableA
where IDno in (29)
Why is this taking 5 minutes? I do not understand the order the in which the Select statements are processed or what is causing the delay.

How can I optimize this query?

The only solution I know is to build a temp table from the two Selects which return the value 29 and to then use an inner join to use it as part of the main Select.

Thanks in advance for you assistance.

pat


Start Free Trial
[+][-]06.19.2007 at 06:45PM PDT, ID: 19321492

View this solution now by starting your 30-day free trial. Setting up your free trial is quick, easy, and secure. We will return you to this solution, unlocked, when you're done.

 

About this solution

Zone: MS SQL Server
Tags: select, nested, performance
Sign Up Now!
Solution Provided By: dqmq
Participating Experts: 4
Solution Grade: A
 
 
[+][-]06.19.2007 at 07:59PM PDT, ID: 19321707

At Experts Exchange, members can ask their questions to thousands of technology professionals, also known as Experts. Experts compete and collaborate to answer those questions by leaving comments like this one.

Start your 30-day free trial to view this Expert Comment or ask the Experts your question.

 
[+][-]06.19.2007 at 08:09PM PDT, ID: 19321740

At Experts Exchange, members can ask their questions to thousands of technology professionals, also known as Experts. Experts compete and collaborate to answer those questions by leaving comments like this one.

Start your 30-day free trial to view this Expert Comment or ask the Experts your question.

 
[+][-]06.19.2007 at 09:32PM PDT, ID: 19322094

At Experts Exchange, members can ask their questions to thousands of technology professionals, also known as Experts. Experts compete and collaborate to answer those questions by leaving comments like this one.

Start your 30-day free trial to view this Expert Comment or ask the Experts your question.

 
[+][-]06.19.2007 at 10:24PM PDT, ID: 19322224

At Experts Exchange, members can ask their questions to thousands of technology professionals, also known as Experts. Experts compete and collaborate to answer those questions by leaving comments like this one.

Start your 30-day free trial to view this Expert Comment or ask the Experts your question.

 
[+][-]06.20.2007 at 04:15AM PDT, ID: 19323468

Often, when Experts are collaborating with members who have asked questions, they will request additional information about the problem. Askers respond with an author comment like this one.

Start your 30-day free trial to view this Author Comment or ask the Experts your question.

 
[+][-]06.20.2007 at 05:27AM PDT, ID: 19323910

At Experts Exchange, members can ask their questions to thousands of technology professionals, also known as Experts. Experts compete and collaborate to answer those questions by leaving comments like this one.

Start your 30-day free trial to view this Expert Comment or ask the Experts your question.

 
[+][-]06.20.2007 at 09:09AM PDT, ID: 19325860

At Experts Exchange, members can ask their questions to thousands of technology professionals, also known as Experts. Experts compete and collaborate to answer those questions by leaving comments like this one.

Start your 30-day free trial to view this Expert Comment or ask the Experts your question.

 
[+][-]06.20.2007 at 09:32AM PDT, ID: 19326061

At Experts Exchange, members can ask their questions to thousands of technology professionals, also known as Experts. Experts compete and collaborate to answer those questions by leaving comments like this one.

Start your 30-day free trial to view this Expert Comment or ask the Experts your question.

 
 
Loading Advertisement...
20081112-EE-VQP-44