Tech or Treat! Write an article about your scariest tech disaster to win gadgets!Learn more

x
?
Solved

Can I speed up these queries

Posted on 2011-03-09
3
Medium Priority
?
254 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
[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
3 Comments
 
LVL 15

Accepted Solution

by:
derekkromm earned 1000 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 1000 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

Free Tool: Subnet Calculator

The subnet calculator helps you design networks by taking an IP address and network mask and returning information such as network, broadcast address, and host range.

One of a set of tools we're offering as a way of saying thank you for being a part of the community.

Question has a verified solution.

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

Access custom database properties are useful for storing miscellaneous bits of information in a format that persists through database closing and reopening.  This article shows how to create and use them.
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.
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…
Access reports are powerful and flexible. Learn how to create a query and then a grouped report using the wizard. Modify the report design after the wizard is done to make it look better. There will be another video to explain how to put the final p…

647 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