If this is your first visit, be sure to check out the FAQ by clicking the link above. You may have to register before you can post: click the register link above to proceed. To start viewing messages, select the forum that you want to visit from the selection below.

 
Go Back  dBforums > Database Server Software > MySQL > query problem

Reply
 
LinkBack Thread Tools Search this Thread Display Modes
  #1 (permalink)  
Old 10-22-05, 14:17
rockyroad rockyroad is offline
Registered User
 
Join Date: Nov 2004
Posts: 9
query problem

Could someone help me with this

I want to combine the following 2 queries into 1 query where it would give me 2 results (proflad and proftot) but don't know how

select sum(return-inv)as proflad
from allbets where com="lad"


select sum(return-inv)as proftot
from allbets where com="tot"


thanks
Reply With Quote
  #2 (permalink)  
Old 10-22-05, 15:28
jfulton jfulton is offline
Registered User
 
Join Date: Apr 2005
Location: Baltimore, MD
Posts: 297
This should work:
Code:
SELECT
(select sum(return-inv) from allbets where com="lad") as proflad
, (select sum(return-inv) from allbets where com="tot") as proftot
Reply With Quote
  #3 (permalink)  
Old 10-22-05, 15:56
rockyroad rockyroad is offline
Registered User
 
Join Date: Nov 2004
Posts: 9
I tried that but I still get an error message

Error: You have an error in your SQL syntax..............

Any other ideas?

Thanks
Reply With Quote
  #4 (permalink)  
Old 10-22-05, 17:48
megaultraninja megaultraninja is offline
Registered User
 
Join Date: Oct 2005
Posts: 5
version of mysql

I believe that sub selects are supported from 4.1 and higher, so check your version.
Reply With Quote
  #5 (permalink)  
Old 10-23-05, 08:47
rockyroad rockyroad is offline
Registered User
 
Join Date: Nov 2004
Posts: 9
I have version 4.0.16

Is there any way I can run this query with this?
Reply With Quote
  #6 (permalink)  
Old 10-23-05, 13:40
megaultraninja megaultraninja is offline
Registered User
 
Join Date: Oct 2005
Posts: 5
pretty sure, you can't

can you not updrade?
Reply With Quote
  #7 (permalink)  
Old 10-23-05, 20:32
jfulton jfulton is offline
Registered User
 
Join Date: Apr 2005
Location: Baltimore, MD
Posts: 297
The only other thing I can think of would be something like:

Code:
select
sum(return_inv) as return_inv, com 
from allbets 
where com="lad" OR com="tot"
group by com
but the results will be returned as two separate rows (rather than one row in two columns).
Reply With Quote
Reply

Thread Tools Search this Thread
Search this Thread:

Advanced Search
Display Modes

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is Off
HTML code is Off
Trackbacks are On
Pingbacks are On
Refbacks are On