Please look to this picture
http://i.stack.imgur.com/A2RB2.jpg
i want to get
- sum of money in table come
- sum of money in table leave
- inner join emp using id
Thats my query
SELECT uid,SUM(money) FROM come
INNER JOIN emp ON(come.uid = emp.id)
WHERE emp.statue=1
GROUP BY come.uid
UNION
SELECT uid,SUM(money) FROM `leave`
INNER JOIN emp ON ( leave.uid = emp.id )
GROUP BY leave.uid
and the result was this image
Another way to do it (not tested, so let me know if it blows up):
I don't know which'll be faster compared to Kevin's. You might want to
explain
them both and see.Try this
I don't have mySQL installed on this PC, but this should get you close. Depending on the result of the above, you might need to wrap the entire query above in another group by...
here we go: