» Quick Links
You can make money on these forums
We Share profits with you
Google
Google Adsense
Google Adwords
YPN
Yahoo
MSN Search
Web Directories
Web Hosting
Web Hosting Offers
Hosting News
Suggestions
Link Building
Domain Names
PHP Forums
MySQL Forums
» More Links
OSP News
Reseller Hosting
Shared Hosting
Dedicated Servers
Google Adsense
Search Engine Marketing
Link Development
Affiliate Marketing


» Advertising
Multiple DC PR Check

Free SEO Tools


Go Back   Webmaster Forums > Website Developement / Programming > MySQL Forums

MySQL Forums Share Your Ideas and Tips about MYSQL. Ask questions about MYSQL. Table Design and Much More...

Reply
 
Thread Tools Display Modes
  #1  
Old 05-13-2007, 05:37 AM
skrawler skrawler is offline
Junior Member
 
Join Date: May 2007
Posts: 1
Thanks: 0
Thanked 0 Times in 0 Posts
Rep Power: 0
skrawler is on a distinguished road
Default single select question?

Hey there,

I must have a single select execute 2 sums, from two different tables.

For example:
SELECT
tbl1.ID as ID,
SUM(tbl1.value1) AS Money_Earned,
SUM(tbl2.value2) AS Money_Spent
FROM
income tbl1, expenses tbl2
WHERE
tbl1.ID = tbl2.ID
GROUP BY
tbl1.ID

I get a table back in the form I expect, but instead of a sum, I'm getting a product of the number of entries in the table that meet the criteria * the sum of those values.

Please help! What am I doing wrong?
Thankz. -- This message may have been cut off and the rest will only be shown to members. To become a member, click here --
Reply With Quote
Revenue Sharing Ads ( ?):
  #2  
Old 05-14-2007, 04:32 AM
Kodi Kodi is offline
Senior Member
 
Join Date: Jul 2006
Posts: 116
Thanks: 0
Thanked 0 Times in 0 Posts
Rep Power: 18
Kodi is on a distinguished road
Default Re: single select question?

I guess you must try to make the JOIN condition explicit:

SELECT
tbl1.ID as ID,SUM(tbl1.value1) AS Money_Earned, SUM(tbl2.value2)

AS Money_Spent
FROM
income tbl1
JOIN tbl2 ON tbl2.ID = tbl1.ID
GROUP BY
tbl1.ID -- This message may have been cut off and the rest will only be shown to members. To become a member, click here --
Reply With Quote
Reply


Thread Tools
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

vB code is On
Smilies are On
[IMG] code is On
HTML code is Off
Forum Jump

Similar Threads
Thread Thread Starter Forum Replies Last Post
single set clause.. Lias MySQL Forums 1 12-12-2006 04:39 AM
nested select statement. PowerX MySQL Forums 1 09-30-2006 07:45 AM
MySQL Select Date comparisons functions? features? rice MySQL Forums 1 08-22-2006 02:21 PM
Error in select statement speedy PHP Programming and Tips 1 08-19-2006 10:32 AM
select querry question yogesh MySQL Forums 2 07-30-2006 12:02 PM


All times are GMT. The time now is 11:06 PM.