homepage Welcome to WebmasterWorld Guest from 54.226.192.202
register, free tools, login, search, pro membership, help, library, announcements, recent posts, open posts,
Become a Pro Member

Home / Forums Index / Code, Content, and Presentation / Databases
Forum Library, Charter, Moderator: open

Databases Forum

    
MySQL sum query with inner joins
nickCR

5+ Year Member



 
Msg#: 4402450 posted 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.
Home ¦ Free Tools ¦ Terms of Service ¦ Privacy Policy ¦ Report Problem ¦ About ¦ Library ¦ Newsletter
WebmasterWorld is a Developer Shed Community owned by Jim Boykin.
© Webmaster World 1996-2014 all rights reserved