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

Newbie: how to speed up this simple query

Hello dear readers,

I have 2 tables, let's say
first table: "Appointment", which has 3 fields (I've simplified the schema for better understanding)
ID as GUID
(the key)
Length as Float
TaskID as GUID
((external key)

The second table is called "Task" and has 2 fields (again, simplified schema)
ID as GUID (key)
RequiredLength as Float
Now the problem:
In a kind of "Tasks to plane view", I'm pretty sure I can speed things up since I recall a Sum on each criteria .. I'v tried to use alias, but propably missed something because I only get error message on return ("Invalid Column name").

Here is my query
Expand|Select|Wrap|Line Numbers
  1. SELECT     Task.ID, Task.RequiredLength, 
  2.                           (SELECT     SUM(Length) AS Expr1
  3.                             FROM          Appointment
  4.                             WHERE      (TaskID = Task.ID)
  5.                             GROUP BY TaskID) AS PlannedLength
  6. FROM         Task 
  7. WHERE     ((SELECT     SUM(Length) AS Expr1
  8.                          FROM         Appointment AS Appointment_1
  9.                          WHERE     (TaskID = Task.ID)
  10.                          GROUP BY TaskID) < RequiredLength)
  11.  OR ((SELECT     SUM(Length) AS Expr1
  12.                          FROM         Appointment AS Appointment_1
  13.                          WHERE     (TaskID = Task.ID)
  14.                          GROUP BY TaskID) ) IS NULL
  15.  
  16. I have tried the following query, but it does not work :  
  17. SELECT     Task.ID, Task.RequiredLength, 
  18.                           (SELECT     SUM(Length) AS Expr1
  19.                             FROM          Appointment
  20.                             WHERE      (TaskID = Task.ID)
  21.                             GROUP BY TaskID) AS PlannedLength
  22. FROM         Task 
  23. WHERE     ((PlannedLength < RequiredLength) OR (PlannedLength IS NULL))
'************************************************* ****************
Any help would be greatly appreciated, I'm a real newbie :
Thank for your answers,
Happy coding
Aug 16 '07 #1
6 1755
code green
1,726 Expert 1GB
A sub query is inherently slow.
They can usually be replaced by a much faster JOIN.
This looks like it could be re-written as a JOIN.
If you are prepared to make an attempt I will help you along.
Aug 16 '07 #2
Thank you Code green,

As I said, any help would ge appreciated, so feel free to show me a few guideline or a straight solution for that query

Thank you in advance
Regards
Aug 16 '07 #3
code green
1,726 Expert 1GB
Are you really trying to improve the performance of this query?
I doubt it works.
I can't re-write it because I can't work out what you are trying to do.
Aug 16 '07 #4
Ok, thank you for your help anyway
Aug 16 '07 #5
code green
1,726 Expert 1GB
I would like to have a go but I just don't have time to study your query.
Can you describe what you are trying to achieve?
Aug 16 '07 #6
pbmods
5,821 Expert 4TB
Heya, François.

Please use CODE tags when posting source code. See the REPLY GUIDELINES on the right side of the page next time you post.
Aug 16 '07 #7

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

Similar topics

17
by: Shailesh Humbad | last post by:
I just posted an article I wrote called ASP Speed Tricks. It covers techniques to optimize output of database data in HTML, for both simple tables and complex tables. More advanced ASP authors...
0
by: fugue | last post by:
Hello- We are trying to use mysql in some very high speed applications. To get an Idea of how fast it could run, we did a test query on a table with one row only (and also a zero row table if...
5
by: JENS CONSER | last post by:
Hello NG, We have a performance problem in using a client server solution based on MS SQL-Server 2000 through a VPN tunnel (via broadband internet connection). The SQL Server is running on a...
2
by: jphelan | last post by:
Ever since I successfully applied some techniques for increasing the speed of my 17 meg. Application; it has only made me hunger for more. First, let me list what I have done so far: 1. Split...
27
by: SQL Learner | last post by:
Hi all, I have an Access db with two large tables - 3,100,000 (tblA) and 7,000 (tblB) records. I created a select query using Inner Join by partial matching two fields (X from tblA and Y from...
2
by: UnderCoverGuy | last post by:
Hello. I am trying to produce a SQL report query that determines the type (model) of system a user has and based off of that information, CASE selects to determine the amount of and type of memory...
13
by: Ciaran | last post by:
Hi All, Is it faster to have mySql look up as much data as possible in one complex query or to have php do all the complex processing and submit lots of simple queries to the mysql database? ...
1
by: Raycaster | last post by:
I'm 3/4 finished 2 simple VB apps for a upcoming silent auction being held at my children's school. Very Simple - This is what it does: 1st app allows input and builds a text database Unit...
2
by: Eraser | last post by:
Hello, I'm just starting to learn PL/SQL. To get my feet wet, I'm trying to write a simple stored procedure that takes some values as parameters, and inserts those values into a table. For...
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: aa123db | last post by:
Variable and constants Use var or let for variables and const fror constants. Var foo ='bar'; Let foo ='bar';const baz ='bar'; Functions function $name$ ($parameters$) { } ...
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...
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...
0
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,...
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.