homepage Welcome to WebmasterWorld Guest from 54.198.224.121
register, free tools, login, search, subscribe, help, library, announcements, recent posts, open posts,
Accredited PayPal World Seller

Home / Forums Index / Code, Content, and Presentation / Databases
Forum Library, Charter, Moderators: physics

Databases Forum

    
MySQL sum query with inner joins
nickCR




msg:4402452
 6:40 pm on Dec 30, 2011 (gmt 0)

Hello All,

Having a problem in MySQL with a Query.

So here's a data example:

tbl1
id, id2, id3, idTbl2
1, 3, 4, 23
2, 3, 4, 24
3, 3, 4, 25
4, 3, 4, 26

tbl2
id, name, donation
23, test, 12
24, test, 12
25, test, 12
26, test, 12

I have a query that looks something like this:

SELECT sum(tbl2.donation)
FROM tbl1
INNER JOIN tbl2 ON tbl1.idTbl2 = tbl2.id
WHERE tbl1.id1 = 3
AND tbl1.id2 = 4

Obviously the sum is adding donations for all rows from tbl2. However because tbl1.id1 and tbl1.id2 is the same for each I only want it to consider the donation one time. Any ideas?

 

Global Options:
 top home search open messages active posts  
 

Home / Forums Index / Code, Content, and Presentation / Databases
rss feed

All trademarks and copyrights held by respective owners. Member comments are owned by the poster.
Terms of Service ¦ Privacy Policy ¦ Report Problem ¦ About
© Webmaster World 1996-2014 all rights reserved