473,385 Members | 1,337 Online
Bytes | Software Development & Data Engineering Community
Post Job

Home Posts Topics Members FAQ

Join Bytes to post your question to a community of 473,385 software developers and data experts.

Speeding Up My Query

I have designed a form to bridge one customer record with a master customer record in a table. For example:

CustomerName, CustomerNumber:
ABC Company, 101;
ABC Corp. , 102;
ABC Inc., 103;
ABC Co., 104;
ABC Comp., 105;

MasterCustomerName, MasterCustomerNum:

ABC Master, 1001

Bridge:
101, 1001;
102, 1001;
103, 1001;
104, 1001;
105, 1001

To give me the customers that have not yet been assigned to a Master Record, I wrote query that looks at a table and finds all customer numbers that are not in the Bridge table:
Expand|Select|Wrap|Line Numbers
  1. "SELECT DISTINCT CUSTOMER_NBR, CUSTOMER_NAME
  2. FROM tblX
  3. WHERE NOT Exists (SELECT BridgeCustomerNumber, From tblCustomerBridge WHERE BridgeCustomerNumber = CUSTOMER_NBR)
  4. ORDER BY CUSTOMER_NAME;"
tblX has approx 500,000 records and it is taking about 10 to 12 seconds to run the query. I have to refresh the query every time I use the form to update the Bridge Table.

Any advice on how to speed up the runtime of the query?

Thanks in advance,

bplantes
Feb 26 '08 #1
3 1790
Stewart Ross
2,545 Expert Mod 2GB
...tblX has approx 500,000 records and it is taking about 10 to 12 seconds to run the query. I have to refresh the query every time I use the form to update the Bridge Table.
Hi. Subqueries are very useful for certain tasks, but on large datasets the use of a subquery can lead to a performance hit as you are finding. As an alternative without the subquery, try the following, changing the field names to the proper ones before you do so:
Expand|Select|Wrap|Line Numbers
  1. SELECT tblX.[Customer No], tblX.[Customer Name]
  2. FROM tblX LEFT JOIN Bridge ON tblX.[Customer No] = Bridge.Customer_Nbr
  3. WHERE (((Bridge.Customer_Nbr) Is Null))
  4. ORDER BY tblX.[Customer Name];
  5.  
  6.  
I don't know how it will perform on 500,000 records but the left-joined tables where all we want to find are nulls at the bridge end should be faster than the subquery I reckon.

-Stewart
Feb 26 '08 #2
Thanks for that... I have worked with MS SQL before and have used "Left Outer Join" which would only take the left, non-joined, records. Access doesn't seem to have that functionality. I just implemented this into the code and it worked great. Thanks for the help.
Feb 27 '08 #3
NeoPa
32,556 Expert Mod 16PB
MS SQL's LEFT [OUTER] JOIN (where the OUTER keyword is optional) is equivalent to Access's LEFT JOIN.
Feb 28 '08 #4

Sign in to post your reply or Sign up for a free account.

Similar topics

6
by: Angel Faus | last post by:
Hi all, We've got an Oracle database in a Web application. Intermedia Text queries are an important part of the usage and work fine. The problem is that in order to generate a certain web...
0
by: Bennett Haselton | last post by:
I have a MySQL query running inside a CGI script on my site that, at random intervals, seems to take 10-20 seconds to complete instead of less than 1 second. I spent so much time trying to track...
0
by: Apollo | last post by:
I have about 20K records that result from the following query. Front end for the database is ACCESS97 and pulling up 20K records makes a huge performance hit. For the form in question I am using...
3
by: David | last post by:
Consider this SQL Query: ----------------------------------------------------------------- SELECT c.CASE_NBR, DATEDIFF(d, c.CREATE_DT, GETDATE()) AS Age, c.AFFD_RCVD, c.PRV_CRD_ISS, x.RegE,...
3
by: John D | last post by:
We have a dynamic SP that dependant on a user name will run a selected tailored to them. One of the criteria is the number of rows retrieved, which we include using 'top @varNoOfRows' in the...
9
by: mfyahya | last post by:
Hi, I'm new to databases :) I need help speeding up select queries on my data which are currently taking 4-5 seconds. I set up a single large table of coordinates data with an index on the fields...
2
by: Wayne | last post by:
I am running a complex query using about 25 criteria that are entered on a query form. If any individual criteria isn't required its field is left as "*" on the form. When I run the query the...
2
by: simon_w3 | last post by:
Hi All, I'm trying to figure out how I can speed up a fragment of code (which has been converted from vb6 to .NET) that reads data from a database. My knowledge on database programming is...
11
by: Dan Sugalski | last post by:
Is there any good way to speed up SQL that uses like and has placeholders? Here's the scoop. I've got a system that uses a lot of pre-generated SQL with placeholders in it. At runtime these SQL...
0
by: Faith0G | last post by:
I am starting a new it consulting business and it's been a while since I setup a new website. Is wordpress still the best web based software for hosting a 5 page website? The webpages will be...
0
by: ryjfgjl | last post by:
In our work, we often need to import Excel data into databases (such as MySQL, SQL Server, Oracle) for data analysis and processing. Usually, we use database tools like Navicat or the Excel import...
0
by: taylorcarr | last post by:
A Canon printer is a smart device known for being advanced, efficient, and reliable. It is designed for home, office, and hybrid workspace use and can also be used for a variety of purposes. However,...
0
by: Charles Arthur | last post by:
How do i turn on java script on a villaon, callus and itel keypad mobile phone
0
by: ryjfgjl | last post by:
If we have dozens or hundreds of excel to import into the database, if we use the excel import function provided by database editors such as navicat, it will be extremely tedious and time-consuming...
0
by: emmanuelkatto | last post by:
Hi All, I am Emmanuel katto from Uganda. I want to ask what challenges you've faced while migrating a website to cloud. Please let me know. Thanks! Emmanuel
1
by: nemocccc | last post by:
hello, everyone, I want to develop a software for my android phone for daily needs, any suggestions?
1
by: Sonnysonu | last post by:
This is the data of csv file 1 2 3 1 2 3 1 2 3 1 2 3 2 3 2 3 3 the lengths should be different i have to store the data by column-wise with in the specific length. suppose the i have to...
0
by: Hystou | last post by:
There are some requirements for setting up RAID: 1. The motherboard and BIOS support RAID configuration. 2. The motherboard has 2 or more available SATA protocol SSD/HDD slots (including MSATA, M.2...

By using Bytes.com and it's services, you agree to our Privacy Policy and Terms of Use.

To disable or enable advertisements and analytics tracking please visit the manage ads & tracking page.