Solved

Can I speed up these queries

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

Ransomware-A Revenue Bonanza for Service Providers

Ransomware – malware that gets on your customers’ computers, encrypts their data, and extorts a hefty ransom for the decryption keys – is a surging new threat.  The purpose of this eBook is to educate the reader about ransomware attacks.

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.
You need to know the location of the Office templates folder, so that when you create new templates, they are saved to that location, and thus are available for selection when creating new documents.  The steps to find the Templates folder path are …
Learn how to number pages in an Access report over each group. Activate two pass printing by referencing the pages property: Add code to the Page Footers OnFormat event to capture the pages as there occur for each group. Use the pages property to …
With Secure Portal Encryption, the recipient is sent a link to their email address directing them to the email laundry delivery page. From there, the recipient will be required to enter a user name and password to enter the page. Once the recipient …

690 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