Solved

Can I speed up these queries

Posted on 2011-03-09
3
239 Views
Last Modified: 2012-05-11
I have been working in many different access 2003 databases all with a SQL2000 backend with linked tables. In these database I keep running accross the same type of queries. they run very slowly and I think there must be away to rewrite these. Can anyone show me a better way? I created the example of the queries and the final query. I will post them all.  query4 in this example is the main query to run.
query1
SELECT Table1.AAA, Table1.BBB, Table1.CCC, Table1.DD, Table1.EE
FROM Table1;

query2
SELECT Table2.AAA, Table2.BBB, Table2.CCC, Table2.FF, Table2.GG
FROM Table2;

query3_union
SELECT Table1.AAA, Table1.BBB, Table1.CCC
FROM Table1
UNION SELECT Table2.AAA, Table2.BBB, Table2.CCC
FROM Table2;

query4
SELECT Query3_Union.AAA, Query3_Union.BBB, Query3_Union.CCC, Query1.DD, Query1.EE, Query2.FF, Query2.GG
FROM (Query3_Union LEFT JOIN Query1 ON (Query3_Union.AAA = Query1.AAA) AND (Query3_Union.BBB = Query1.BBB) AND (Query3_Union.CCC = Query1.CCC)) LEFT JOIN Query2 ON (Query3_Union.AAA = Query2.AAA) AND (Query3_Union.BBB = Query2.BBB) AND (Query3_Union.CCC = Query2.CCC);

Open in new window

0
Comment
Question by:Keking
3 Comments
 
LVL 15

Accepted Solution

by:
derekkromm earned 250 total points
ID: 35085315
create nonclustered indexes on table1 and table2 on AAA, BBB, CCC and include DD/EE or FF/GG as secondary columns

the statement would look like this:

create nonclustered index ix_Table1 on table1 (AAA, BBB, CCC) include (DD, EE)
create nonclustered index ix_Table2 on table1 (AAA, BBB, CCC) include (FF, GG)
0
 
LVL 74

Expert Comment

by:Jeffrey Coachman
ID: 35085383
Can you clearly define "they run very slowly" in chronological terms please?

Is this slowness the total time to run all the queries?, or just one?

There are many things that will contribute to "Slowness:
Do you have your indexes optimized?
How many records are you dealing with?
What is the network Architecture?
How are you running the queries?
...etc
0
 
LVL 50

Assisted Solution

by:Lowfatspread
Lowfatspread earned 250 total points
ID: 35086910
look at indexes but ...  (can't use include until sql 2005...)

wouldn't a pass thru query of

select coalesce(a.aaa,b.aaa) as aaa
       ,coalesce(a.bbb,b.bbb) as bbb
 ,coalesce(a.ccc,b.ccc) as ccc
,a.dd.a.ee.b.ff.b.gg
from table1 as a
full outer join table2 as b
on a.aaa=b.aaa
and a.bbb=b.bbb
and a.ccc-b.ccc
order by 1,2,3

be a better solution?

ie let sql server do all the IO/retrieval...
0

Featured Post

PRTG Network Monitor: Intuitive Network Monitoring

Network Monitoring is essential to ensure that computer systems and network devices are running. Use PRTG to monitor LANs, servers, websites, applications and devices, bandwidth, virtual environments, remote systems, IoT, and many more. PRTG is easy to set up & use.

Question has a verified solution.

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

Introduction The Visual Basic for Applications (VBA) language is at the heart of every application that you write. It is your key to taking Access beyond the world of wizards into a world where anything is possible. This article introduces you to…
Preparing an email is something we should all take special care with – especially when the email is for somebody you may not know very well. The pressures of everyday working life stacked with a hectic office environment can make this a real challen…
Familiarize people with the process of utilizing SQL Server views 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 Access…
In Microsoft Access, learn different ways of passing a string value within a string argument. Also learn what a “Type Mis-match” error is about.

808 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