Welcome to WebmasterWorld Guest from 54.226.241.8

Forum Moderators: open

Message Too Old, No Replies

MySQL sum query with inner joins

     

nickCR

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

5+ Year Member



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?
 

Featured Threads

Hot Threads This Week

Hot Threads This Month