Review your favorite Linux distribution.
Go Back > Forums > Non-*NIX Forums > Programming
User Name
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.


  Search this Thread
Old 09-21-2011, 06:25 PM   #1
Registered: Sep 2003
Location: Qingdao, China
Distribution: mandriva, slack, red flag
Posts: 249

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
account.managerId='7156251143' and
account.customerId=accountGoogleMS.googleAccount and'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 06:34 PM.
Old 09-21-2011, 07:35 PM   #2
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?


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 11:05 PM
LXer: Learn how to join tables in MySQL LXer Syndicated Linux News 0 08-08-2006 04:21 PM
mysql reinstallation distorted by previous tables in /var/mysql mad4linux Linux - Software 0 10-04-2005 02:39 PM
MySQL tables from 4.0 to 3.0 michaelbhahn Linux - Software 0 08-31-2004 11:23 AM
mysql tables noord28 Linux - Newbie 0 02-20-2003 03:56 AM > Forums > Non-*NIX Forums > Programming

All times are GMT -5. The time now is 03:40 PM.

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