Solved

query is slow returning the result

Posted on 2007-03-18
4
182 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
  • 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

Free Gift Card with Acronis Backup Purchase!

Backup any data in any location: local and remote systems, physical and virtual servers, private and public clouds, Macs and PCs, tablets and mobile devices, & more! For limited time only, buy any Acronis backup products and get a FREE Amazon/Best Buy gift card worth up to $200!

Join & Write a Comment

This article is a continuation or rather an extension from Cascading Combos (http://www.experts-exchange.com/A_5949.html) and builds on examples developed in detail there. It should be understandable alone, but I recommend reading the previous artic…
In a multiple monitor setup, if you don't want to use AutoCenter to position your popup forms, you have a problem: where will they appear?  Sometimes you may have an additional problem: where the devil did they go?  If you last had a popup form open…
As developers, we are not limited to the functions provided by the VBA language. In addition, we can call the functions that are part of the Windows operating system. These functions are part of the Windows API (Application Programming Interface). U…
In Microsoft Access, learn the trick to repeating sub-report headings at the top of each page. The problem with sub-reports and headings: Add a dummy group to the sub report using the expression =1: Set the “Repeat Section” property of the dummy…

757 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

19 Experts available now in Live!

Get 1:1 Help Now