473,385 Members | 1,707 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.

Need assistance debugging this query

296 100+
Whats wrong in the following query -->

Expand|Select|Wrap|Line Numbers
  1. SELECT SUM(bookings),SUM(invoices),SUM(segments),SUM(totalgross),SUM(totalsale),SUM(commission),SUM(tax),SUM(SELECT grossfare FROM salesqww where type="cash adjustments" and aircode="UA") FROM summary WHERE aircode='UA'
Mar 13 '07 #1
13 1528
ronverdonk
4,258 Expert 4TB
Your thread title should be a synopsis of the problem you have.

Instead of letting our members solve a puzzle, what is the problem you have with the statement?

Ronald :cool:
Mar 13 '07 #2
pankajit09
296 100+
Your thread title should be a synopsis of the problem you have.

Instead of letting our members solve a puzzle, what is the problem you have with the statement?

Ronald :cool:
I have nested a query inside the SUM .

I want to take the SUM of the column returned by that query.
Is it possible ?
Mar 13 '07 #3
ronverdonk
4,258 Expert 4TB
I have nested a query inside the SUM .

I want to take the SUM of the column returned by that query.
Is it possible ?
I know what you want to do!
I want to know what error is returned by MySQL!

Ronald :cool:
Mar 13 '07 #4
Atli
5,058 Expert 4TB
Hi.

First of all let me congratulate you on the least usefull discussion name I've seen in my time here.

That said, I'd try replacing all double quote marks " with single quote marks '
Mar 14 '07 #5
pankajit09
296 100+
Hi.

First of all let me congratulate you on the least usefull discussion name I've seen in my time here.

That said, I'd try replacing all double quote marks " with single quote marks '
I didn't get you .

May be I got your first line but not the second.
Mar 14 '07 #6
pankajit09
296 100+
I know what you want to do!
I want to know what error is returned by MySQL!

Ronald :cool:
The error which comes is to use to use the RIGHT syntax near the nested query.
Mar 14 '07 #7
Atli
5,058 Expert 4TB
Sub-queries need to be inside (), and altho your Query is inside a pair of those, that particular pair belongs to the SUM() function.

So adding a second () arround your sub-query might fix the problem.

O yea and what I said before apears to be wrong, I was under the impression that MySQL would slap you in the head for doing "this", rather than 'this'... but apparently it is possible now.
Would be good practice tho to pick one of them and stick to it.
Mar 14 '07 #8
pankajit09
296 100+
Sub-queries need to be inside (), and altho your Query is inside a pair of those, that particular pair belongs to the SUM() function.

So adding a second () arround your sub-query might fix the problem.

I added a second () but it doesn't work.
Mar 15 '07 #9
Can you give me your table structure
Mar 16 '07 #10
Atli
5,058 Expert 4TB
I think I may have guessed the probblem.

The sub-querie you nested inside the SUM() function returns multiple rows. Sub-queryies (as far as I've seen) may only return one row.

So I belive moving your sub-query out of the SUM function, while placing a SUM function inside your sub-query will give you the results you want.

Somewhat like this: (I reformatted the query to better understand it)
Expand|Select|Wrap|Line Numbers
  1. SELECT 
  2.   SUM(bookings),
  3.   SUM(invoices),
  4.   SUM(segments),
  5.   SUM(totalgross),
  6.   SUM(totalsale),
  7.   SUM(commission),
  8.   SUM(tax),
  9.   ( SELECT 
  10.       SUM(grossfare) 
  11.     FROM 
  12.       salesqww 
  13.     WHERE 
  14.       type="cash adjustments" 
  15.     AND 
  16.       aircode="UA"
  17.   ) 
  18. FROM 
  19.   summary 
  20. WHERE 
  21.   aircode='UA'
  22.  
P.S. This had been easilly spotted by myself and many of our friends here if you had added the error message in with your post.
So please, if this does not fix it, give us error messages. We like error messages :)
Mar 16 '07 #11
pankajit09
296 100+
I think I may have guessed the probblem.

The sub-querie you nested inside the SUM() function returns multiple rows. Sub-queryies (as far as I've seen) may only return one row.

So I belive moving your sub-query out of the SUM function, while placing a SUM function inside your sub-query will give you the results you want.

Somewhat like this: (I reformatted the query to better understand it)
Expand|Select|Wrap|Line Numbers
  1. SELECT 
  2.   SUM(bookings),
  3.   SUM(invoices),
  4.   SUM(segments),
  5.   SUM(totalgross),
  6.   SUM(totalsale),
  7.   SUM(commission),
  8.   SUM(tax),
  9.   ( SELECT 
  10.       SUM(grossfare) 
  11.     FROM 
  12.       salesqww 
  13.     WHERE 
  14.       type="cash adjustments" 
  15.     AND 
  16.       aircode="UA"
  17.   ) 
  18. FROM 
  19.   summary 
  20. WHERE 
  21.   aircode='UA'
  22.  
P.S. This had been easilly spotted by myself and many of our friends here if you had added the error message in with your post.
So please, if this does not fix it, give us error messages. We like error messages :)
So which will be more efficient -->

The above query which you mentioned

OR

Two seperate queries ?
Mar 16 '07 #12
Atli
5,058 Expert 4TB
I'd reccomend the sub-query.
Making two queries will require more code in you application and you will have to query the database twice.
Mar 16 '07 #13
pankajit09
296 100+
I'd reccomend the sub-query.
Making two queries will require more code in you application and you will have to query the database twice.
I don't think the sub query is fast.

I tested it and found out that its slow compared to two seperated queries.
Mar 20 '07 #14

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

Similar topics

2
by: lawrence | last post by:
I've been bad about documentation so far but I'm going to try to be better. I've mostly worked alone so I'm the only one, so far, who's suffered from my bad habits. But I'd like other programmers...
5
by: Bill | last post by:
Good Day; I would appreciate assistance developing a query that I haven't been able to develop without using a second table. I wish to count the number of records that are still open on the...
1
by: Dalan | last post by:
I'm experiencing a Query Syntax Error with an Access 97 Db. Actually, the query performs as expected when adding any new records or editing existing ones and even deleting records, EXCEPT when the...
2
by: Kenny G | last post by:
Below is the code I currently have to either skip a control or go to a control based on the response in the complications control. The problem is even when Me.Complications is "None" the cursor...
0
by: ward | last post by:
Greetings. Ok, I admit it, I bit off a bit more than I can chew. I need to complete this "Generate Report" page for my employer and I'm a little over my head. I could use some additional...
2
by: William Foster | last post by:
Good morning all, I was wondering if anyone knows how to modify code whilst debugging in Miscrosoft Visual Basic 2003 .NET, in Microsoft Excel Visual Basic for Applications I am able to edit all...
1
by: Scubadude | last post by:
I am looking for some assistance in 'fine-tuning' my preferences as I set-up my system to learn PHP. I am running Komodo professional, version 3.5.3, build 262321, platform win32-x86. Under...
7
by: Rnykster | last post by:
I know a little about Access and have made several single table databases. Been struggling for about a month to do a multiple table database with no success. Help! There are two tables. First...
1
by: DR | last post by:
What ports do i need to unblock on client and server (running msvsmon.exe) to debug remotely from my client box with visual studio 2005 pro? When I attach to remote process a connection shows up...
1
by: CloudSolutions | last post by:
Introduction: For many beginners and individual users, requiring a credit card and email registration may pose a barrier when starting to use cloud servers. However, some cloud server providers now...
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
isladogs
by: isladogs | last post by:
The next Access Europe User Group meeting will be on Wednesday 3 Apr 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 former...
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: 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:
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
0
BarryA
by: BarryA | last post by:
What are the essential steps and strategies outlined in the Data Structures and Algorithms (DSA) roadmap for aspiring data scientists? How can individuals effectively utilize this roadmap to progress...
1
by: nemocccc | last post by:
hello, everyone, I want to develop a software for my android phone for daily needs, any suggestions?

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.