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

mutiple table sum problem

I am having a problem getting my resultset to come out right. I am
looking to join 3 tables getting a sum out of two and data out of the
the third:

Tables:
users
debits
credits

These tables have a common userid key and I am looking to have the
resultset look like:

name email sum(credits) sum(debits)

The data looks something like:

users-
123 Joe jo*@joe.com 123Main

debits-
123 10
123 20

credits
123 3
123 6
123 9

The problem I am having is that a UNION gives me:

Joe jo*@joe.com 30 0
Joe jo*@joe.com 0 18

My Join looks like this:

Joe jo*@joe.com 90 36

What I want is:

Joe jo*@joe.com 30 18

Here is my real SQL:

mysql>
SELECT first_name, sum(c.credits), sum(d.debits)
FROM users
LEFT OUTER JOIN all_credits c USING (userid)
LEFT OUTER JOIN all_debits d ON ( orders.userid=users.userid )
group by users.userid;

OR

mysql>
( select first_name, sum(c.credits), 0 from users
LEFT OUTER JOIN all_credits c using (userid) group by users.userid)
UNION ( select first_name, 0, sum(d.debits) from all_debits d
LEFT OUTER JOIN orders using (userid) group by users.userid) ;
Thanks for any help.
Mark
Jul 19 '05 #1
0 1303

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

Similar topics

4
by: topjun | last post by:
using osql to apply SPs in mutiple threads Hello, I got a weird problem when I was using osql to apply scripts for msde database in multiple threads mode. Sometime 2 sps were missing during the...
1
by: Steve | last post by:
Hi all Ok then I have searched through the back postings for a while now on google and read some interesting stuff on how to model a typical client / order db however.... My problem is that I...
3
by: Hai Nguyen | last post by:
Hi all I was attempting to insert multiple row by using a loop into a database.A table has 2 primary keys and one regular field (PR) (PR) ID Project Ans 1 2 a 1 ...
4
by: Cindy H | last post by:
Hi I'm using an access database and vb.net I have been using the following type of function to get data from one table. This is working great - Public Shared Function GetAllLotsForSale()...
2
by: underground | last post by:
I need a little help figuring this one out. I have a script that should post mutiple binary files into a single row but instead of copying the indiviuals files it rewrites the first file to all the...
10
by: underground | last post by:
I need a little help figuring this one out. I have a script that I've modified to post mutiple binary files into a single row but instead of copying the indiviuals files it rewrites the first file to...
7
by: shanmugamit | last post by:
hi, i using mutiple check box but i didn't get all value... as $res=mysql_query("select * from cie where des='Resource Pipeline Associate' order by name"); $j=0;...
13
nabh4u
by: nabh4u | last post by:
hi, I am trying to insert multiple rows in a table using PL/SQL. I have two procedures and two tables. the first procedure gets the data from the source table, manipulates it and then sends the...
6
by: dewraj | last post by:
Hi I am using windows applicaiton(.net) as front end, and I want to get mutiple tables in Dataset by executing a single stored procedure i.e. SP would return mutiple tables (record sets) with the...
1
by: chennaibala | last post by:
can any one send me mutiple image upload program and save the file name with extension in mysql table.we must cheak uploaded file type like bmp or any image file while uploading. i develop...
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: 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: 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: Charles Arthur | last post by:
How do i turn on java script on a villaon, callus and itel keypad mobile phone
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?
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...

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.