473,757 Members | 9,145 Online
Bytes | Software Development & Data Engineering Community
+ Post

Home Posts Topics Members FAQ

slow query in access and in vb datareport

Hello,
I need to extract the names of the employees which have not been active
during the last 3 months from the following tables

EMPLOYEES:
employee_id
name

COOPERATIVE
cooperative_id
company_name

HOURS
employee_id
customer_id
year_month <-- e.g. 06/2006 (Date/Time field)
regular_hours
nightly_hours

I need to know the names of the employees which either do not appear in the
HOURS table in the last three months or do appear but have 0 total hours
(regular+nightl y) in the three months.
The following is the way I got the result, but it is definitely too slow: it
starts displaying the results in the query results, but it hangs when I
change record page.

SELECT distinct name, company_name from employees a, cooperative b
where a.cooperative_i d=b.cooperative _id AND a.employee_id not in
(SELECT distinct hours.employee_ id FROM hours where year_month>#06/2006#
group by employee_id HAVING sum(regular_hou rs+nightly_hour s)=0)

Why is this query so slow? I have:
16000 rows in HOURS,
2000 rows in employees
10 rows in cooperative

How may I get the same result with a faster query ?
Thank you
Regards

Sep 30 '06 #1
1 1869
"Generale Cluster" <al************ ***@unsampdoria nosoftmasters.n etha
scritto nel messaggio news:ef******** **@newsreader.m ailgate.org...
Hello,
I need to extract the names of the employees which have not been active
during the last 3 months from the following tables

EMPLOYEES:
employee_id
name

COOPERATIVE
cooperative_id
company_name

HOURS
employee_id
customer_id
year_month <-- e.g. 06/2006 (Date/Time field)
regular_hours
nightly_hours

I need to know the names of the employees which either do not appear in
the
HOURS table in the last three months or do appear but have 0 total hours
(regular+nightl y) in the three months.
The following is the way I got the result, but it is definitely too slow:
it
starts displaying the results in the query results, but it hangs when I
change record page.
Finally I got it:
I also had a mistake in the having condition, but I've found a faster
construct instead of NOT IN:

select a.employee_id, name from employyes a left join (SELECT distinct
hours.employee_ id FROM hours where year_month>#06/2006#
group by employee_id HAVING sum(regular_hou rs+nightly_hour s)<>0) AS b on
a.lavoratore_id =b.lavoratore_i d WHERE b.lavoratore_id is null order by name

This is extremely faster.
Regards




Sep 30 '06 #2

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

Similar topics

11
17569
by: DJJ | last post by:
I am using the MySQL ODBC 3.51 driver to link three relatively small MySQL tables to a Microsoft Access 2003 database. I am finding that the data from the MySQL tables takes a hell of a long time to load making any kind linkage with my Access data virtually useless. I have the MySQL driver setup in as a USER DSN. The MySQL data is sitting out on a server and the Access database is running locally. The network connection is very...
0
1100
by: Cady Steldyn | last post by:
I need to run a data report that will query an Access_Table that has the following Project info: My Form has a command_button with the following code: Private Sub Command1_Click() Set db = New Connection db.CursorLocation = adUseClient db.Open "PROVIDER=MSDataShape;Data
3
4804
by: Janross | last post by:
I'm having trouble with a query that's prohibitively slow. On my free-standing office computer it's fine (well, 2-4 seconds), but on the client's network, it takes at least 5 minutes to run. Obviously not workable! I know where the problem is, I just don't know how to fix it. The query calls a function, and I assume it gets slow because the function runs on every record. So--is there a way to rewrite the function so it's quicker?...
12
7591
by: VMI | last post by:
For some reason, the process of retrieving data (about 20 records) from an Access table that has 400K records to a dataTable is taking over 3 mins. to complete. Below is my code to connect to the DB and query the table. The table "audit" primary key is "Line". Another weird thing (but I guess that's another post) is that, while it's doing the dataset Fill, my PC is slowed done substantially. But I don't know why that would happen since...
0
2625
by: roiavidan | last post by:
Hi, I'm having a bit of a problem with a small application I wrote in C#, which uses an Access database (mdb file) for storing financial data. After looking for a similiar topic and failing to find one, I'm posting the question in hope some one of you guys out there will have the answer for me...! I'll start with what I have, then I'll continue to the problem itself.
6
5378
by: klove1209 | last post by:
Good afternoon, Can someone please tell me how I can return records from a query. I have text fields that I need to obtain, and have those necessary records sent to MS Word. I need to return the data that is in MainSectionLabel, MainLabel and SummaryTextBox. Here is what I have so far: Public Function gettbldata() Dim strSQL As String
3
1855
by: suresh_punniyakkodi | last post by:
Hello to all, How to pass SQL Query to DataReport at Runtime... Please, Any body help for this Question... Regards, Suresh...
4
1906
by: ashutoshvyas | last post by:
I am designing a data report in VB6. In data environment it is possible to selet tables and 'select quries'. But I want to generate a report based on parameters passed by user, so i had created a parameter query in ACCESS which is not available in the properties of command1. SQL code of query is as under : SELECT Customers.account_no, Customers.card_no, Customers.name, payments.amount, payments.payment_date, dlt_3., total_amount. FROM...
2
9840
by: existential.philosophy | last post by:
This is a new problem for me: I have some queries that open very slowly in design view. My benchmark query takes about 20 minutes to open in design view. That same query takes about 20 minutes to open in datasheet view. As an experiment, I deleted all rows in all tables; after that, the query took only seconds to open in both design view and datasheet view. From these facts, I conclude that Access is evaluating the query when I go to...
0
9489
marktang
by: marktang | last post by:
ONU (Optical Network Unit) is one of the key components for providing high-speed Internet services. Its primary function is to act as an endpoint device located at the user's premises. However, people are often confused as to whether an ONU can Work As a Router. In this blog post, we’ll explore What is ONU, What Is Router, ONU & Router’s main usage, and What is the difference between ONU and Router. Let’s take a closer look ! Part I. Meaning of...
0
9298
by: Hystou | last post by:
Most computers default to English, but sometimes we require a different language, especially when relocating. Forgot to request a specific language before your computer shipped? No problem! You can effortlessly switch the default language on Windows 10 without reinstalling. I'll walk you through it. First, let's disable language synchronization. With a Microsoft account, language settings sync across devices. To prevent any complications,...
0
9906
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 tapestry of website design and digital marketing. It's not merely about having a website; it's about crafting an immersive digital experience that captivates audiences and drives business growth. The Art of Business Website Design Your website is...
1
9885
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
9737
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
7286
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
5172
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...
1
3829
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
3
3399
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.