473,804 Members | 2,136 Online
Bytes | Software Development & Data Engineering Community
+ Post

Home Posts Topics Members FAQ

An inefficient query

Background: Access 2003 (converted from A97 DB recently), database is
split into FE/BE with the FE residing on client machine.

I've got a question about how I can possibly optimize a query I've
built. This may seem relatively straight forward to some of you more
experienced programmers, but I'm almost entirely self-taught. This
means that I have some gaps in my knowledge and sometimes go about
doing things the hard way never knowing there was a quicker and easier
way to do it.

I have two tables involved in the query: tblIssue (12,000 records) and
tblIssueHistory (85,000 records). The tblIssue table holds issues and
tblIssueHistory holds a history of (locations/specific owners/time in
and time out) where these issues have been in. One issue may have many
historical locations in tblIssueHistory .

Very frequently I need to display some key information whenever an
issue is displayed. Most notably I need to display the very first and
very last record (origination and current) location associated with an
issue from tblIssueHistory .

The current process that I use now first queries (lets call this
qryOriginator) tblIssueHistory using the sum function to group on
IssueID (foreign key to tblIssue) and show the Min of HistID (primary
key of tblIssueHistory ). Another nearly identical query is run,
except it pulls the max of HistID (call this qryCurrent). At this
point, I create another query to pull in tblIssue, add qryOriginator
and qryCurrent, then link qryOriginator and qryCurrent to
tblIssueHistory to allow access to the rest of the fields (like
department, name of owner, time in and time out).

It pulls up the information I want, but it takes much too long to do
so (between 6 and 30 seconds). When added to other criteria I need to
run to display the info needed, it makes a bad situation even worse.
Compounding this is the fact that I expect the number of records I'll
need to house to triple or quadruple in the next year, so I'm getting
desperate to make this database run more efficiently.

I'm wondering if there is a more efficient approach I could take to
get at the first and last record for each issueID. The only thing I
can think of is to add fields to tblIssue to hold originator and
current owner names, then modify them whenever an issue's location
moves. I had done it this way originally, but had trouble keeping the
data consistent with info in tblIssueHistory and switched it up.

Any advice any of you might have will be greatly appreciated!

Oct 8 '07 #1
1 1983
An***********@b cbsmn.com wrote:
Background: Access 2003 (converted from A97 DB recently), database is
split into FE/BE with the FE residing on client machine.

I've got a question about how I can possibly optimize a query I've
built. This may seem relatively straight forward to some of you more
experienced programmers, but I'm almost entirely self-taught. This
means that I have some gaps in my knowledge and sometimes go about
doing things the hard way never knowing there was a quicker and easier
way to do it.

I have two tables involved in the query: tblIssue (12,000 records) and
tblIssueHistory (85,000 records). The tblIssue table holds issues and
tblIssueHistory holds a history of (locations/specific owners/time in
and time out) where these issues have been in. One issue may have many
historical locations in tblIssueHistory .

Very frequently I need to display some key information whenever an
issue is displayed. Most notably I need to display the very first and
very last record (origination and current) location associated with an
issue from tblIssueHistory .

The current process that I use now first queries (lets call this
qryOriginator) tblIssueHistory using the sum function to group on
IssueID (foreign key to tblIssue) and show the Min of HistID (primary
key of tblIssueHistory ). Another nearly identical query is run,
except it pulls the max of HistID (call this qryCurrent). At this
point, I create another query to pull in tblIssue, add qryOriginator
and qryCurrent, then link qryOriginator and qryCurrent to
tblIssueHistory to allow access to the rest of the fields (like
department, name of owner, time in and time out).

It pulls up the information I want, but it takes much too long to do
so (between 6 and 30 seconds). When added to other criteria I need to
run to display the info needed, it makes a bad situation even worse.
Compounding this is the fact that I expect the number of records I'll
need to house to triple or quadruple in the next year, so I'm getting
desperate to make this database run more efficiently.

I'm wondering if there is a more efficient approach I could take to
get at the first and last record for each issueID. The only thing I
can think of is to add fields to tblIssue to hold originator and
current owner names, then modify them whenever an issue's location
moves. I had done it this way originally, but had trouble keeping the
data consistent with info in tblIssueHistory and switched it up.

Any advice any of you might have will be greatly appreciated!
Sure. Create a query. Open up a new query and drag the history table
into it. Drag the IssueID to a column and drag the HistoryID to two
columns. Make the names MinID, MaxID. Ex:
MinID : HistoryID
MaxID : HistoryID.

From the menu, select View/Totals. In the first column of HistoryID,
in the Totals row, select Min from the dropdown. Select Max to the next.

Save the query. You can now link this to the recordsource of the form
to have access to MinID/MaxID.

Of course, another method would be to use a subform...if you have space.
When you go to an issue record all records from history are displayed.
If you have record selectors on the subform the folks can hit the
first/last record navigation buttons...and they can see anything inbetween.

If you don't have space, you can always create a form to diplay the
history table as a datasheet or continuous form and when you need to see
that info, have a button to display the records in history from that issue.
Docmd.Openform "History",,,"Is sueID = " & Me.IssueID

You should be able to get this to display near instantaneously . If not,
you probably have not indexed fields that need to be indexed.
Oct 8 '07 #2

This thread has been closed and replies have been disabled. Please start a new discussion.

Similar topics

4
1480
by: Stefan Berglund | last post by:
I've noticed that most examples offered in this group tend to use Response.Write to spit out the HTML rather than switch between script and HTML. I also came across an article intimating the same idea. Is this considered inefficient? <%If (IsArray(ar)) Then Const cNumber = 0 Const cHorse = 1 Const cOwner = 2 Const cTrainer = 3 Const cRider = 4 Const cHorseID = 5
1
1275
by: Mike Ridley | last post by:
Suppose I have a customer table ("customer"):- Primary Key cust_id long integer cust_name text(40) cust_type text(1) containing 80000 rows. There are about 10000 rows where customer type = "A" To retrieve these rows I use query Select * from customer where cust_type = get_type()
9
2493
by: Javaman59 | last post by:
Using local declarations within a block often makes code more readable, but is it less efficient? eg... void P() { while (...) { int i = ...; bool b = ...; .... } }
6
1596
by: ImOk | last post by:
I am using Windows IIS with PHP5 CGI. When I want to use an extension in PHP5 under Windows I enable the extension line in PHP.INI. (e.g. extension=php_sqlite.dll). Does PHP load all the extensions in the PHP.INI on every invocation of a request? If I have 20 different extensions not all of them are used on every page request. Is this inefficient? Would using dl() be more efficient? And why is it being depracated under 5?
13
2001
by: TS | last post by:
Say i have a class car with properties: Color, Make, Model, Year, DriverID And a Driver class with properties: DriverID, Name The driverID PRIVATE property is the id of the driver from say a driver table (t_driver). This has a PUBLIC property accessor called Driver My understanding of OO using the composition model is that when you want to load up a car class, you would access the DB to get Color, make, Model, Year, DriverID and load...
2
1948
by: Baller4lifeII | last post by:
Hey there, I've been chasing a problem for the project that I'm working on and was able to narrow it down to the ORDER BY clause in my query. The algorithm looks like this, I take a range of time selected by the user and I need to do some calculations on the items within that range of time. However, before I calculate, I need to query for the most recent row of a specified item before that time range. So my Query statement ends up...
0
1226
by: moltendorf | last post by:
Alright, I finally worked up a massive SQL query that gets me the result I want for my PHP 6 CMS: Module Engine Class. I have read various comments within the dev.mysql.com documentation of MySQL 5.0 on JOIN, IN, and certain subqueries being much faster if done in a different form. So even though I'm fairly sure this wont be much of a burden if one uses my CMS with a fairly normal amount of modules installed (maybe a couple hundred or so...
8
2742
by: Bryan | last post by:
I want my business objects to be able to do this: class Person(base): def __init__(self): self.name = None @base.validator def validate_name(self): if not self.name: return
5
1914
by: jeddiki | last post by:
Hello, I have been writing procedural php for a couple of years and I have quite lot of little scrips that I use in different large scripts. I'll give and example I display the category menu on onmany pages so I have this little php file:
0
10603
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, it seems that the internal comparison operator "<=>" tries to promote arguments from unsigned to signed. This is as boiled down as I can make it. Here is my compilation command: g++-12 -std=c++20 -Wnarrowing bit_field.cpp Here is the code in...
1
10356
by: Hystou | last post by:
Overview: Windows 11 and 10 have less user interface control over operating system update behaviour than previous versions of Windows. In Windows 11 and 10, there is no way to turn off the Windows Update option using the Control Panel or Settings app; it automatically checks for updates and installs any it finds, whether you like it or not. For most users, this new feature is actually very convenient. If you want to control the update process,...
0
10099
tracyyun
by: tracyyun | last post by:
Dear forum friends, With the development of smart home technology, a variety of wireless communication protocols have appeared on the market, such as Zigbee, Z-Wave, Wi-Fi, Bluetooth, etc. Each protocol has its own unique characteristics and advantages, but as a user who is planning to build a smart home system, I am a bit confused by the choice of these technologies. I'm particularly interested in Zigbee because I've heard it does some...
1
7643
isladogs
by: isladogs | last post by:
The next Access Europe User Group meeting will be on Wednesday 1 May 2024 starting at 18:00 UK time (6PM UTC+1) and finishing by 19:30 (7.30PM). In this session, we are pleased to welcome a new presenter, Adolph Dupré who will be discussing some powerful techniques for using class modules. He will explain when you may want to use classes instead of User Defined Types (UDT). For example, to manage the data in unbound forms. Adolph will...
0
6869
by: conductexam | last post by:
I have .net C# application in which I am extracting data from word file and save it in database particularly. To store word all data as it is I am converting the whole word file firstly in HTML and then checking html paragraph one by one. At the time of converting from word file to html my equations which are in the word document file was convert into image. Globals.ThisAddIn.Application.ActiveDocument.Select();...
0
5536
by: TSSRALBI | last post by:
Hello I'm a network technician in training and I need your help. I am currently learning how to create and manage the different types of VPNs and I have a question about LAN-to-LAN VPNs. The last exercise I practiced was to create a LAN-to-LAN VPN between two Pfsense firewalls, by using IPSEC protocols. I succeeded, with both firewalls in the same network. But I'm wondering if it's possible to do the same thing, with 2 Pfsense firewalls...
0
5675
by: adsilva | last post by:
A Windows Forms form does not have the event Unload, like VB6. What one acts like?
1
4314
by: 6302768590 | last post by:
Hai team i want code for transfer the data from one system to another through IP address by using C# our system has to for every 5mins then we have to update the data what the data is updated we have to send another system
2
3836
muto222
by: muto222 | last post by:
How can i add a mobile payment intergratation into php mysql website.

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.