Solved

query is slow returning the result

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

NEW Veeam Agent for Microsoft Windows

Backup and recover physical and cloud-based servers and workstations, as well as endpoint devices that belong to remote users. Avoid downtime and data loss quickly and easily for Windows-based physical or public cloud-based workloads!

Question has a verified solution.

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

In Part II of this series, I will discuss how to identify all open instances of Excel and enumerate the workbooks, spreadsheets, and named ranges within each of those instances.
Traditionally, the method to display pictures in Access forms and reports is to first download them from URLs to a folder, record the path in a table and then let the form or report pull the pictures from that folder. But why not let Windows retr…
In Microsoft Access, learn how to “cascade” or have the displayed data of one combo control depend upon what’s entered in another. Base the dependent combo on a query for its row source: Add a reference to the first combo on the form as criteria i…
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…

624 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