473,386 Members | 1,773 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,386 software developers and data experts.

How to optimise query by using integers and not text comparisons?

374 256MB
Hi all,

I have installed a simple progress meter on one of my forms which contains a lot of inline sql queries to bring up around 40 different statistics.

One group however brings up the number of injuries based on body location, department occurred in and the date to be viewed. I have noticed the progress bar takes longest during the execution of this part of the code.

The sql is as follows:

Expand|Select|Wrap|Line Numbers
  1. SELECT Count(*) AS CountOfInjuryID1
  2. FROM ((tbldept INNER JOIN (tblLocations INNER JOIN tblhselog ON tblLocations.LocationID = tblhselog.Incident_location) ON tbldept.DeptID = tblLocations.OwningDept) INNER JOIN tblInjuredPerson ON tblhselog.HSEID = tblInjuredPerson.HSEIDLINK) INNER JOIN (tblBodypart INNER JOIN tblInjuryInvestigation ON tblBodypart.PartID = tblInjuryInvestigation.InjuryLocation) ON tblInjuredPerson.InjuredPersonID = tblInjuryInvestigation.InjuredPersonLinkID
  3. WHERE (((tblhselog.Incident_date) Between fiscalStartDate('February',2011) And fiscalEndDate('February',2011)) AND ((tblBodypart.BodyPart)='Head/Face/Eye') AND ((tbldept.Department)='HS&E'));
There are about 6 different tables joined here to get from a department of where an injury occurred through to the location on the body that was injured.

I can not shorten the amount of steps needed to be taken to do this but I was wondering, at present I use text values to match records. Would my query be quicker if I used the integer values of the records instead?

E.g.:

Instead of searching for "Head/Face/Eye" which in table tblBodyParts is all within one row (it doesnt need to be normalised further as we use Head/Face/Eye as a single grouping) as my second column (text) where my first column is autonumber. Would it be better to search based on the Primary Key? (integer value).

I don't know whether access queries search better based on numbers rather than text
Jan 26 '11 #1

✓ answered by Rabbit

Using * is quicker.

Comparing against an indexed integer would be quicker as well. Although if you index the text fields you're comparing on, there's not going to be a huge difference.

What's probably taking the most time is all the inner joins. You can drop tblDept and tblBodyPart from the joins and filter on the foreign key column, assuming they're indexed.

5 1416
jimatqsi
1,271 Expert 1GB
Yes of course because not only is the primary key an integer value but it is the primary index. But I am wondering if the most benefit might come from changing count(*) to count(someuniquecolumnname); I've never used count(*) but I presume that selects and counts everything. I'd be interested in knowing if that simple change makes all the difference in the world.

Jim
Jan 26 '11 #2
munkee
374 256MB
I have actually read that using * is better
Jan 26 '11 #3
Rabbit
12,516 Expert Mod 8TB
Using * is quicker.

Comparing against an indexed integer would be quicker as well. Although if you index the text fields you're comparing on, there's not going to be a huge difference.

What's probably taking the most time is all the inner joins. You can drop tblDept and tblBodyPart from the joins and filter on the foreign key column, assuming they're indexed.
Jan 26 '11 #4
munkee
374 256MB
I think I will go through all my queries and drop the joins where I can use the foreign key. I coded with the joins as it helped me check inputs and outputs using actual names instead of a bunch of integer keys which I could easily confuse when running the sql inside functions
Jan 26 '11 #5
You should set up your database tables using a foreign key relationship. It'll make things easier in the long run. Also, use stored procedures if you're not already using them.
Jan 27 '11 #6

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

Similar topics

10
by: Alex | last post by:
Hi, How would I go about writing the results of an SQL query to a text file? I cannot find any info in the Online help files. For example, I would like the results of: SELECT * FROM...
1
by: bdt513 | last post by:
I am trying to extract the values from a query using VBA. Specifically, I want to concatenate all the values of the "rosEmail" field from query "qselRosterEmailList" into one string (strEmails). I...
14
by: Darin | last post by:
I have a table that I want to delete specific records from based on data in other tables. I'm more familiar with Access '97, but am now using 2003, but the database is in 2000 format. In '97, I...
0
by: Hrvoje Vrbanc | last post by:
Hello all! I'm new to ASP.NET 2.0 and I tried connecting and inserting to a SQL database by using SqlDataSource control. I build an INSERT query using the query builder tool but I'm puzzled...
13
by: forbes | last post by:
Hi, I have a user that used the Query Wizard to create a query in Access. Now she claims that her master table is missing all the data that was excluded from the query. Can you create anything...
6
markmcgookin
by: markmcgookin | last post by:
Hi Folks, I am running a simple query using VB (This isnt a VB Question, dont worry!) on SQL Server Compact. I have the query below being created, and then added to if a flower location doesn't...
1
by: EwanD | last post by:
I am trying to read through and process an Access Query using VBA. I have used the OpenRecordset method with parameters as below OpenRecordset(sSourceRecordset, dbOpenDynaset) Where...
3
by: Chris McFarling | last post by:
What's the most efficient method to export the result set of a SQL query to a text file using ASP.NET? There could potentially be a few thousand rows.
3
by: bdavid50 | last post by:
I have an ODBC to several tables in an Oracle 10g installation. I created an Access 2003 query using several of the tables from that ODBC. When I created it, it worked as expected and returned the...
2
by: tomric | last post by:
I have a question on passing data to the criteria of a parameter of a parameter query using VBA. I have a query set up that has ten different fields in it. One is field named “status”, this field...
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: ryjfgjl | last post by:
In our work, we often receive Excel tables with data in the same format. If we want to analyze these data, it can be difficult to analyze them because the data is spread across multiple Excel files...
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?
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...
0
Oralloy
by: Oralloy | last post by:
Hello folks, I am unable to find appropriate documentation on the type promotion of bit-fields when using the generalised comparison operator "<=>". The problem is that using the GNU compilers,...
0
jinu1996
by: jinu1996 | last post by:
In today's digital age, having a compelling online presence is paramount for businesses aiming to thrive in a competitive landscape. At the heart of this digital strategy lies an intricately woven...

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.