Solved

Can I speed up these queries

Posted on 2011-03-09
3
232 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

How your wiki can always stay up-to-date

Quip doubles as a “living” wiki and a project management tool that evolves with your organization. As you finish projects in Quip, the work remains, easily accessible to all team members, new and old.
- Increase transparency
- Onboard new hires faster
- Access from mobile/offline

Join & Write a Comment

Suggested Solutions

Title # Comments Views Activity
SQL Backup skipping a few tables 7 29
How to get the MS access function DSUM to work? 4 32
Resize text 4 17
Error in SQL Query 36 39
Overview: This article:       (a) explains one principle method to cross-reference invoice items in Quickbooks®       (b) explores the reasons one might need to cross-reference invoice items       (c) provides a sample process for creating a M…
In this article I will describe the Backup & Restore method as one possible migration process and I will add the extra tasks needed for an upgrade when and where is applied so it will cover all.
Familiarize people with the process of retrieving data from SQL Server using an Access pass-thru query. Microsoft Access is a very powerful client/server development tool. One of the ways that you can retrieve data from a SQL Server is by using a pa…
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…

743 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

10 Experts available now in Live!

Get 1:1 Help Now