Solved

query is slow returning the result

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

Master Your Team's Linux and Cloud Stack!

The average business loses $13.5M per year to ineffective training (per 1,000 employees). Keep ahead of the competition and combine in-person quality with online cost and flexibility by training with Linux Academy.

Question has a verified solution.

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

It’s been over a month into 2017, and there is already a sophisticated Gmail phishing email making it rounds. New techniques and tactics, have given hackers a way to authentically impersonate your contacts.How it Works The attack works by targeti…
As tax season makes its return, so does the increase in cyber crime and tax refund phishing that comes with it
Familiarize people with the process of utilizing SQL Server stored procedures 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 Micr…
In Microsoft Access, learn how to use Dlookup and other domain aggregate functions and one method of specifying a string value within a string. Specify the first argument, which is the expression to be returned: Specify the second argument, which …

777 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