Still celebrating National IT Professionals Day with 3 months of free Premium Membership. Use Code ITDAY17

x
?
Solved

query is slow returning the result

Posted on 2007-03-18
4
Medium Priority
?
193 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 2000 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

Quick Start: DOCKER

Sometimes you just need a Quick Start on a topic in order to begin using it.. this is just what you need to know to get up and running with Docker!

Question has a verified solution.

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

AutoNumbers should increment automatically, without duplicates.  But sometimes something goes wrong, and the next AutoNumber value is a duplicate.  This article shows how to recover from this problem.
An alternative to the "For XML" way of pivoting and concatenating result sets into strings, and an easy introduction to "common table expressions" (CTEs). Being someone who is always looking for alternatives to "work your data", I came across this …
With Microsoft Access, learn how to specify relationships between tables and set various options on the relationship. Add the tables: Create the relationship: Decide if you’re going to set referential integrity: Decide if you want cascade upda…
Visualize your data even better in Access queries. Given a date and a value, this lesson shows how to compare that value with the previous value, calculate the difference, and display a circle if the value is the same, an up triangle if it increased…

704 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