LinuxQuestions.org
Help answer threads with 0 replies.
Go Back   LinuxQuestions.org > Forums > Non-*NIX Forums > Programming
User Name
Password
Programming This forum is for all programming questions.
The question does not have to be directly related to Linux and any language is fair game.

Notices

Reply
 
Search this Thread
Old 09-21-2011, 05:25 PM   #1
secretlydead
Member
 
Registered: Sep 2003
Location: Qingdao, China
Distribution: mandriva, slack, red flag
Posts: 248

Rep: Reputation: 31
mysql join three tables


i have a query that joins three tables.

i've written two queries that work, but can't figure out how to put them together:

select accountGoogleMS.MSAccount
from db.account join db.accountGoogleMS join db.costMS
where
account.managerId='7156251143' and
account.customerId=accountGoogleMS.googleAccount and
costMS.date='2011-09-09'
group by accountGoogleMS.MSAccount order by account.customerId;
+-----------+
| MSAccount |
+-----------+
| X8888333 |
| X8888444 |
+-----------+

select sum(spend) from db.costMS where (accountNumber = 'X8888333' or accountNumber='X8888444') and date='2011-09-09';

+------------+
| sum(spend) |
+------------+
| 173.67 |
+------------+


I've tried a few different ways and can't figure it out...

Last edited by secretlydead; 09-21-2011 at 05:34 PM.
 
Old 09-21-2011, 06:35 PM   #2
Proud
Senior Member
 
Registered: Dec 2002
Location: England
Distribution: Used to use Mandrake/Mandriva
Posts: 2,794

Rep: Reputation: 116Reputation: 116
Use decent joins, with on not where clauses.

Is the same sum result wanted next to each row of the grouped output? Or should the sum for each individual accountNumber be on each row within the groups?

Basically, can you express your table schemas & relationships and describe the result you're after?
 
  


Reply


Thread Tools Search this Thread
Search this Thread:

Advanced Search

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


Similar Threads
Thread Thread Starter Forum Replies Last Post
Joining three tables using left and normal join mohtasham1983 Programming 2 07-23-2008 10:05 PM
LXer: Learn how to join tables in MySQL LXer Syndicated Linux News 0 08-08-2006 03:21 PM
mysql reinstallation distorted by previous tables in /var/mysql mad4linux Linux - Software 0 10-04-2005 01:39 PM
MySQL tables from 4.0 to 3.0 michaelbhahn Linux - Software 0 08-31-2004 10:23 AM
mysql tables noord28 Linux - Newbie 0 02-20-2003 02:56 AM


All times are GMT -5. The time now is 10:30 AM.

Main Menu
My LQ
Write for LQ
LinuxQuestions.org is looking for people interested in writing Editorials, Articles, Reviews, and more. If you'd like to contribute content, let us know.
Main Menu
Syndicate
RSS1  Latest Threads
RSS1  LQ News
Twitter: @linuxquestions
identi.ca: @linuxquestions
Facebook: linuxquestions Google+: linuxquestions
Open Source Consulting | Domain Registration