Solved

query is slow returning the result

Posted on 2007-03-18
4
188 Views
Last Modified: 2011-10-03
Hello guys,

I have this query in access and it is slow to return the result.
I added some index but I could notice that its performance was not satisfactory.
CESTPAL has 880 rows
CADPAL has 7500 rows

Is there another way to do it where I can improve the result speed?

SELECT COUNT(*) AS TOTAL
FROM CADPAL AS A
WHERE A.CP_CODIGO IS NOT NULL
AND (A.CP_CODUSO="SI" OR A.CP_CODUSO='20')
AND EXISTS (Select C.CS_CODPAL FROM CESTPAL C
                     Where (C.CS_CODUSO="SI" or C.CS_CODUSO='20')
                     and  A.CP_CODIGO = C.CS_CODPAL
                     And C.CS_CODCESTA=51
);
0
Comment
Question by:hidrau
[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
  • 2
  • 2
4 Comments
 
LVL 44

Accepted Solution

by:
GRayL earned 500 total points
ID: 18745717
What is slow?  Does this run any faster?

SELECT Count(*) as Total FROM CADPAL AS a INNER JOIN CESTPAL AS c ON a.CP_CODIGO = c.CS_CODPAL WHERE NOT IsNull(a.CP_CODIGO) AND (a.CP_CODUSO='SI' OR a.CP_CODUSO='20')
AND (c.CS_CODIGO='SI' OR c.CS_CODUSO='20') AND C.CS_CODESTA=51;

0
 
LVL 1

Author Comment

by:hidrau
ID: 18745757
yeah, it ran faster,

I am using exists, what is faster "in" or "exists"?

0
 
LVL 1

Author Comment

by:hidrau
ID: 18745844
thanks,
I changed my code.
0
 
LVL 44

Expert Comment

by:GRayL
ID: 18748613
Thanks, glad I could help.  As you can see, a subquery slows things down.
0

Featured Post

Comprehensive Backup Solutions for Microsoft

Acronis protects the complete Microsoft technology stack: Windows Server, Windows PC, laptop and Surface data; Microsoft business applications; Microsoft Hyper-V; Azure VMs; Microsoft Windows Server 2016; Microsoft Exchange 2016 and SQL Server 2016.

Question has a verified solution.

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

Composite queries are used to retrieve the results from joining multiple queries after applying any filters. UNION, INTERSECT, MINUS, and UNION ALL are some of the operators used to get certain desired results.​
It’s the first day of March, the weather is starting to warm up and the excitement of the upcoming St. Patrick’s Day holiday can be felt throughout the world.
Familiarize people with the process of utilizing SQL Server functions from within Microsoft Access. Microsoft Access is a very powerful client/server development tool. One of the SQL Server objects that you can interact with from within Microsoft Ac…
Show developers how to use a criteria form to limit the data that appears on an Access report. It is a common requirement that users can specify the criteria for a report at runtime. The easiest way to accomplish this is using a criteria form that a…

763 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